【发布时间】:2014-03-12 13:42:37
【问题描述】:
我对 iOS 开发很陌生,问这个问题我可能看起来像个白痴。 但尝试此操作会使应用完全崩溃。
- (IBAction)action:(id)sender
{
if(NSInteger >= 4) {
timer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self selector:@selector(countup)userInfo:nil repeats:YES];
NSLog(@"Action: ‘action' succeeded");
}
else
{
[screen setText:[NSString stringWithFormat:@“You cannot do this."]];
NSLog(@"Action: ‘action' failed");
}
}
计数定义为:
- (void)countup
{
NSInteger += 1;
[screen setText:[NSString stringWithFormat:@"Seconds: %d", NSInteger]];
}
我不知道自己做错了什么,我已经尝试修复了几个小时,但找不到任何对我有帮助的答案。
【问题讨论】:
-
NSInteger >= 4&NSInteger += 1:NSInteger,这是变量名? -
它们的值相同
-
我认为这段代码根本没有运行。
-
@StevenM
NSInteger += 1应该是NSInteger myInt +=1并且你应该遵循整个应用程序NSInteger是类型myInt是你可以操作的实际变量。 -
@sbarow:如果这是应用程序无法编译的原因。但 OP 声称它崩溃。 - (顺便说一句,你可以调用变量
NSInteger,这并不意味着你应该!)
标签: ios objective-c if-statement