应用程序在Objective-C中崩溃

问题描述:

我是Xcode的新手,我似乎无法使其工作......当我构建它时代码中没有错误,但是当我按下链接到下面代码的按钮时整个应用程序崩溃应用程序在Objective-C中崩溃

step当前是int

Xcode是否因此行而崩溃? if (*step == 1 || *step == 2){

这里是我的代码:

-(IBAction)PressOne{ 
    if (*step == 1 || *step == 2){ 
     if ([txtAns.text isEqualToString:@"0"]) 
      txtAns.text = @"1"; 
     else if (![txtAns.text isEqualToString:@"0"]) 
      txtAns.text = [@"1" stringByAppendingString:txtAns.text]; 
    } 
    else { 
     txtAns.text = @"1"; 
     *step = 1; 
    } 
} 
+2

你怎么声明一步?如果你int步骤; ...你可以通过删除*步骤并用步骤替换来修复代码。 –

由于步骤为int,你应该使用步骤引用它的价值,而不是*的一步。

+0

它工作:)在这里,我想整个晚上。谢谢 :) – Malcolm

在使用step之前删除*,整数不是objective-c对象。

当您在使用变量时不需要声明变量时,只需要使用指针表示法(*)。

生成的代码块可能是这样的:

-(IBAction)PressOne{ 
    if (step == 1 || step == 2){ 
     if ([txtAns.text isEqualToString:@"0"]) 
      txtAns.text = @"1"; 
     else if (![txtAns.text isEqualToString:@"0"]) 
      txtAns.text = [@"1" stringByAppendingString:txtAns.text]; 
    } 
    else { 
     txtAns.text = @"1"; 
     step = 1; 
    } 
}