2014-04-15 106 views
-1

* result設置爲返回0或1的布爾值。如果結果返回值1,我想要做的事是讓它記錄下面的語句。將指針與if語句中的整數進行比較

我的日誌顯示它已成功記錄1的結果,但它不會記錄第2條語句「所有設置,讓我們將您發送到MatchCenter」。我不確定第二個if語句是否不在正確的位置,或者語法不正確。任何幫助表示讚賞。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    if (sender != self.nextButton) return; 
    if (self.itemSearch.text.length > 0) { 

     [PFCloud callFunctionInBackground:@"eBayCategorySearch" 
          withParameters:@{@"item": self.itemSearch.text} 
            block:^(NSString *result, NSError *error) { 
             if (!error) { 

              NSLog(@"The result is '%@'", result); 

              if ((int)result == 1) { 
               NSLog(@"All set, let's send you to MatchCenter"); 
              } 

             } 



            }]; 


    } 

    // Get the new view controller using [segue destinationViewController]. 
    // Pass the selected object to the new view controller. 

} 
+0

將'result'投射到'int'就是將指針(內存地址)投射到'int'。這並不是接近將文本值轉換爲「int」的地方。 – rmaddy

回答

1

所以resultNSString這要麼是@"0"@"1"

在這種情況下,要將字符串轉換爲整數,您只需執行[result intValue]。像你在做的那樣施放它是行不通的。

if ([result intValue] == 1) 
{ 
    NSLog(@"All set, let's send you to MatchCenter"); 
} 
+0

不要使用屬性語法來調用非屬性方法。使用'[result intVlaue]'。 – rmaddy

+0

@rmaddy編輯了我的答案,謝謝。在那一個間隔。 – Dima

+0

第二條if語句之前會去哪裏? – KoftaClarence