Reputation:
I have this cocoa touch code where you press a button and a NSInteger adds its self with the number 1 and then a label turnes into the NSInteger value
This is the code
- (IBAction)out:(id)sender {
outnum = outnum + 1;
self.outnumberlabel.text = [[NSString alloc] initWithFormat: @"%d", outnum];
Everything works, but the NsInteger is adding 4 when it is ment to add 1
And when I put in
outnum = outnum + 2;
The label turns to 8
It is going up in fours does anybody know why and how to fix it
Upvotes: 0
Views: 89
Reputation: 11
Check your outnum declaration - you'll see this behaviour if you declare
NSInteger *outnum;
rather than
NSInteger outnum;
Upvotes: 1
Reputation: 16089
It sounds like your out:
method is being called four times more often than you expect. Try putting an NSLog
line in this code to confirm. If that's the case, you'll need to figure out why the method is being called so much.
Upvotes: 0