2011-01-24 92 views
0
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; 
NSLog(@"the response string is %@",responseString); 

if ([responseString isEqualToString:@"No Data Available"]) 
{ 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Message" 
                message:@"No data Avilable in server"delegate:self cancelButtonTitle:nil otherButtonTitles: 
          @"OK", nil]; 
    [alert show]; 
    [alert release]; 

} 

在我的connectiondidfinishload委託方法我有上面的代碼。當服務器回覆沒有數據時,由於某種原因它不會進入if循環。不知道爲什麼。任何提示將不勝感激。 謝謝。無法比較目標c中的responseString

回答

0

ResponseString可能爲null/nil,並且運行時知道if語句將因此而爲false,因此跳過它。您應該與NSLog(@"the response string is %@",responseString);

看到這在一個側面說明,Charles是公司招聘一個很好的調試工具,你可以看到HTTP信息,因爲它熄滅的用武之地。

+0

但我的日誌經常說responseString等於「沒有數據可用」......這是否與NSLOG上方的行中的NSUTF8StringEncoding有關。 – Rajashekar 2011-01-24 10:10:36