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:
Code:
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController {
IBOutlet UILabel * label;
IBOutlet UITextField * textField;
int inum;
}
- (IBAction)increasebuttonPress:(id)sender;
- (IBAction)decreasebuttonPress:(id)sender;
- (IBAction)settextbuttonPress:(id)sender;
@end
and from the m file:
Code:
#import "ViewController.h"
@implementation ViewController
- (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] floatValue] < 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]];
}
}