Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
Hello. I am very new to iPhone development so please excuse me if I don't use correct terminology. I am creating one of my first apps. It is a basic counter that increases or decreases the number on a label when you press the increase or decrease buttons. There is also a text field and a button that when pressed, changes the label to the text in the text field. But after the text field text is changed, when the increase button is pressed, the number doesn't increase from the number I entered in the text field. It increases from the number it last left off on. I want the number to increase from the number I entered in the text field. I know it sounds confusing but please try to help me. Here is some of my code from the h file:
Hello. I am very new to iPhone development so please excuse me if I don't use correct terminology. I am creating one of my first apps. It is a basic counter that increases or decreases the number on a label when you press the increase or decrease buttons. There is also a text field and a button that when pressed, changes the label to the text in the text field. But after the text field text is changed, when the increase button is pressed, the number doesn't increase from the number I entered in the text field. It increases from the number it last left off on. I want the number to increase from the number I entered in the text field. I know it sounds confusing but please try to help me. Here is some of my code from the h file:
- (IBAction)increasebuttonPress:(id)sender; { inum = inum + 1; [label setText:[NSString stringWithFormat:@\"%d\", inum]]; } - (IBAction)decreasebuttonPress:(id)sender; { inum = inum - 1; [label setText:[NSString stringWithFormat:@\"%d\", inum]]; } - (IBAction)settextbuttonPress:(id)sender; { if ([[textField text] [COLOR=\"red\"][B]intValue[/B][/COLOR]] [COLOR=\"red\"][B]<=[/B][/COLOR] 0) { UIAlertView *message = [[UIAlertView alloc] initWithTitle:@\"Error\" message:@\"You can only enter a number greater than 0.\" delegate:nil cancelButtonTitle:@\"OK\" otherButtonTitles:nil]; [message show]; } else { [label setText:[textField text]]; [COLOR=\"Red\"]iNum = [[textField text] intValue];[/COLOR] } }
A couple of things. If you want to require the user to enter a value greater than zero, you should reject anything <= 0, not just <0. Your code as written will allow zero values.<br /> Since your value is an integer, you should probably take the intValue of the text field rather than the float value.
Next, take the textField text and assign it's int value to iNum (changes shown in red)
Regards,
Duncan C WareTo
Animated GIF created with Face Dancer, available for free in the app store.
Replies
Since your value is an integer, you should probably take the intValue of the text field rather than the float value.
Next, take the textField text and assign it's int value to iNum (changes shown in red)
Duncan C
WareTo
Animated GIF created with Face Dancer, available for free in the app store.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome