2011-12-12 75 views
1

我是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步驟; ...你可以通過刪除*步驟並用步驟替換來修復代碼。 –

回答

1

由於步驟爲int,你應該使用步驟引用它的價值,而不是*的一步。

+0

它工作:)在這裏,我想整個晚上。謝謝 :) – Malcolm

1

在使用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; 
    } 
}