2009-11-08 22 views
0

我似乎有一個問題,理解如何有條件地測試從.plist加載到可變陣列的布爾值。我只是不明白我應該做的,並繼續收到錯誤:傳遞numberWithBool的」的說法1:」將指針整數沒有投任何理解這種幫助表示讚賞裝載了.plist文件的MutableArray布爾值。我如何測試True或False?

繼承人我的代碼:!

if ([NSNumber numberWithBool:[[self.ListArray objectAtIndex:indexPath.row] valueForKey:@"TrueFalse"]]) { 
    cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"IsSelected.png"]]; 
} 

回答

0

的方法的NSNumbernumberWithBool:期望一個布爾(BOOL)作爲它的參數。

[[self.ListArray objectAtIndex:indexPath.row] valueForKey:@"TrueFalse"]] apearantly返回除BOOL以外的內容。

要投射eithe將NSNumber或NSString對象轉換爲布爾值,可以使用boolValue方法。

所以,儘量做到以下幾點:

if ([NSNumber numberWithBool:[[[self.ListArray objectAtIndex:indexPath.row] valueForKey:@"TrueFalse"] boolValue]]) { 
     cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"IsSelected.png"]]; 
} 
+0

THX對您有所幫助。我知道我想演員,但是在語法上掙扎。奇怪的是我發現當我的字典存儲YES時出於某種原因,我正在用「!」在「IF」語句中進行測試。不。它的工作原理似乎相反。但現在我正在與它一起。謝謝! – Abbacore

相關問題