2011-08-18 133 views
0

即時解析一個JSON文件。邏輯是這樣的,如果沒有數據名爲boy.it的變量需要進入if循環,並且如果有數據進入else部分。但問題是,即使變量男孩是空的(這表明在控制檯空)環路仍然進入別人part..cud u人幫我out..below是代碼..if語句的問題

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
// Navigation logic may go here. Create and push another view controller. 
NSDictionary *boy=[url objectAtIndex:indexPath.row]; 
NSLog(@"the boy value:%@",boy); 
if (boy == NULL) 
{ 
Secondetailview *detailViewController1 = [[Secondetailview alloc] initWithItem:boy];  
[self.navigationController pushViewController:detailViewController1 animated:YES]; 
[detailViewController1 release];  
}else 
{ 
    FirstViewDetail *detailViewController = [[FirstViewDetail alloc] initWithItem:boy]; 

    [self.navigationController pushViewController:detailViewController animated:YES]; 
    [detailViewController release]; 
} 

} enter image description here

回答

2

我會嘗試使用if (boy == nil)但這似乎並不奏效。

而是做到這一點:

NSString *str = [NSString stringWithFormat:@"%@", boy]; 
if ([str isEqualToString:@""]) { 
    //boy is nil do your stuff 
} 
+0

mkay ......我試着用nil..still無法進入,如果環...做ü沒有的詞典中的任何符號 – kingston

+0

那是絕對一樣的 – hamstergene

+0

-1不正確。 'nil' =='NULL' =='0'(大致在最後一個),因爲Objective-C只是掛在C/C++上。然而,在Objective-C中使用'nil'確實是更正確的:-) – 2011-08-18 05:24:45

-1

如下修改您若條件,看看是否能工程。

((boy == NULL) || ([boy count] == 0)) 
1

更換

if (boy == NULL) 

if ([boy count] == 0) 
+0

dude它不可能..to計數nsdictionary ...它的崩潰 – kingston

+0

你有NSDictionary * boy = [url objectAtIndex:indexPath.row]的問題; 。它不會返回字典.. –

+0

k..if dats如果我試過比較if(url == nil)並獲得相同的結果coz它只有在url數據庫im assingin在字典中的值 – kingston