Need Help With Simple Counting Bug in iPhone SDK
- by seanny94
So I'm basically making an app that adds a count to a number and then displays it each time you tap the button.
However, the first tap issued doesn't take any action but adds one (just as planned) on the second tap. I've searched to the ends of the earth looking for the solution with no luck, so I'll see what you guys can make of this. :)
#import "MainView.h"
@implementation MainView
int count = 0;
-(void)awakeFromNib {
counter.text = @"0";
}
- (IBAction)addUnit {
if(count >= 999) return;
NSString *numValue = [[NSString alloc] initWithFormat:@"%d", count++];
counter.text = numValue;
[numValue release];
}
- (IBAction)subtractUnit {
if(count <= 0) return;
NSString *numValue = [[NSString alloc] initWithFormat:@"%d", count--];
counter.text = numValue;
[numValue release];
}
@end