2011-08-18 22 views
0

私はjsonファイルを解析しています。boy.itという名前の変数にデータがない場合、ロジックはこのようになり、ifループに入る必要があり、データがある場合はelse部分問題.butループはまだコードである他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で

if (boy == NULL) 

を交換して...私は、もしループに入ることがnil..stillことができません使用してみました... U・ディクショナリのためノー任意のシンボルを行います.. – kingston

+0

は全く同じです – hamstergene

+0

-1そうではありません。 Objective-CはC/C++にぶつかっているので、 'nil' ==' NULL' == '0'(おおよそ最後のもの)です。しかし、 'nil'を使うのは、Objective-Cではもっと慣用的に正しいです。:-) –

-1

は、以下のように、あなたの場合は条件を変更し、それが動作するかどうかを確認します。

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

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

あなたはnsdictionaryをカウントすることはできません...そのクラッシュが発生しました – kingston

+0

NSDictionary * boy = [url objectAtIndex:indexPath.row]に問題があります。 。それは辞書を返さない... –

+0

k .. if dats de casesもし私が(URL == nil)と同じ結果を得ることを比較しようとした場合、そのURLの値だけが辞書のassinginにある – kingston