Need Help With Simple Counting Bug in iPhone SDK

Posted by seanny94 on Stack Overflow See other posts from Stack Overflow or by seanny94
Published on 2010-03-20T03:48:52Z Indexed on 2010/03/20 3:51 UTC
Read the original article Hit count: 324

Filed under:
|
|
|

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

© Stack Overflow or respective owner

Related posts about iphone

Related posts about iphone-sdk-3.0