2014-04-15 1 views
-1

* 결과가 0 또는 1의 부울을 반환하도록 설정됩니다. 결과가 1의 값을 반환하면 아래 문을 로그에 기록해야합니다.if 문에서 정수를 가리키는 포인터와 비교

내 기록에 따르면 1의 결과가 성공적으로 기록되고 두 번째 명령문 인 "모든 설정, 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

'int'에'result'를 주조하면 포인터 (메모리 주소)가'int'로 형 변환됩니다. 텍스트 값을'int'로 변환하는 데는 그다지 가깝지 않습니다. – rmaddy

답변

1

그래서 result 중 하나 @"0" 또는 @"1"NSString입니까?

이 경우 문자열을 정수로 변환하려면 [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