2016-01-20 92 views
-1

我對我的Xcode收到錯誤消息 - 目的C.錯誤信息,我不明白

算術上的指針接口「的UILabel」,這是不是對這個架構和平臺大小不變。

if([self checkforwin]){ 
     NSString*winner = nil; 

     if (playertoken==1) 

     winner [email protected]"Player 2 Wins"; 

     _result1 = _result1+1 

     else if (playertoken==2) 

      _result2 = _result2 +1 

      winner [email protected]"Player 1 Wins"; 
     UIAlertView *alert = [[UIAlertView alloc] 
           initWithTitle:@"Result" 
           message: winner 
           delegate:nil 
           cancelButtonTitle:@"Ok" 
           otherButtonTitles: nil]; 
     [self resetboard]; 
     [_audioPlayer play]; 
     [alert show]; 

任何想法如何擺脫他們?

錯誤顯示在result1和result2上。試圖給我的遊戲添加一個分數。

+1

什麼錯誤? –

+0

指向接口「UILabel」的指針的算術,它對於這個體系結構和平臺來說並不是固定的大小。@T – user5806543

+0

是結果uilabel?它在哪裏宣佈? –

回答

1

使用條件時使用括號。也不要設置字符串nil,與空字符串@""

if([self checkforwin]){ 

    NSString *winner = @""; 

    if (playertoken==1) { 

     winner [email protected]"Player 2 Wins"; 
     _result1 = _result1 + 1; 
    } 
    else if (playertoken==2) { 

     winner [email protected]"Player 1 Wins"; 
     _result2 = _result2 + 1; 
    } 

    UIAlertView *alert = [[UIAlertView alloc] 
          initWithTitle:@"Result" 
          message: winner 
          delegate:nil 
          cancelButtonTitle:@"Ok" 
          otherButtonTitles: nil]; 
    [self resetboard]; 
    [_audioPlayer play]; 
    [alert show]; 
} 
+0

你怎麼知道_Result是一個整型變量? –

+1

@ Mr.T在特定變量上應用增量。所以,我認爲這可能是一個整數 –

+0

我已將代碼更改爲上述@MS。但仍顯示錯誤 – user5806543

0

您正在嘗試1添加到UILabel設置。你需要一個整數變量來做增量。任一聲明_result 1和2 int類型的變量或聲明一個整數變量並加一,並把它傳遞給UILabel的.text屬性

_result1 = _result1+1 

這裏_result1必須是一個整數變量。

您需要類似: 聲明RESULT1如int,

@property(assign) int result1; 

和這條線應該是罰款

 _result1=_result1+1;