2013-01-21 71 views
1

如果我用抓在plist中的數據:如何根據條件聲明獲取plist項目?

NSString *path = [[NSBundle mainBundle] pathForResource:@"Providers" ofType:@"plist"]; 
dataArray = [NSMutableArray arrayWithContentsOfFile:path]; 
for (NSDictionary *dictionary in dataArray) 
{ 
    text = [dictionary valueForKey:@"text"]; 
    checked = [dictionary valueForKey:@"checked"]; 
    NSLog(@"%@ checked value is: %@", text, checked); 
} 

我怎麼可能去寫檢查,看看只有檢查設置爲YES如果是這樣輸出的條件語句該供應商

+0

檢查一個BOOL或字符串? –

+0

checked BOOL – hanumanDev

回答

1

假設checked存儲爲BOOL包裹在NSNumber*的文本值,您可以使用此代碼:

NSNumber *checked = [dictionary valueForKey:@"checked"]; 
if ([checked boolValue]) { 
    ... 
} 


*通過調用 [NSNumber numberWithBool:myBoolValue]包裹在一個 NSNumber BOOL

+0

是的,這是一個BOOL值 – hanumanDev

+0

@hanumanDev所以這應該工作,如果沒有,你會看到一個「不響應選擇器」消息的崩潰。你試過了嗎? – dasblinkenlight

+0

它似乎是從plist輸出所有物品。這是我有: 如果([checked boolValue]){NSString * providers = [NSString stringWithFormat:@「%@」,text]; NSLog(@「providers are%@」,providers); NSMutableArray * dataArray2 = [NSMutableArray arrayWithObjects:providers,nil]; (@「providersArray是%@」,dataArray2); } } – hanumanDev