[英]Cocoa touch NSInteger plusing 4 not 1
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 我有这个可可粉触摸代码,您按一下按钮,NSInteger将其自身添加为数字1,然后标签变成NSInteger值
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 一切正常,但是当要添加1时,NsInteger将添加4
And when I put in 当我把
outnum = outnum + 2;
The label turns to 8 标签变成8
It is going up in fours does anybody know why and how to fix it 它涨了四分之一,有人知道为什么以及如何解决它
Check your outnum declaration - you'll see this behaviour if you declare 检查您的outnum声明-如果声明,您将看到此行为
NSInteger *outnum;
rather than 而不是
NSInteger outnum;
It sounds like your out:
method is being called four times more often than you expect. 这听起来像您的out:
方法被调用的频率比您预期的多四倍。 Try putting an NSLog
line in this code to confirm. 尝试在此代码中放入NSLog
行以进行确认。 If that's the case, you'll need to figure out why the method is being called so much. 如果是这样,您将需要弄清楚为什么这么多调用该方法的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.