2009-06-18 18 views
1

下面一段代碼被成功構建,並且對我來說似乎也很好,但不起作用......請注意,我是關鍵值編碼的新手,您的幫助將不勝感激。 .. 在表視圖委託didSelectRowAtIndexPath方法:方法 這裏categoriesList與5個條目NSUnknownKeyException,KVC合規性代碼不能正常工作

NSUInteger row = [indexPath row]; 
NSString *rowString = [categoriesList objectAtIndex:row]; 
NSString *path = [[NSBundle mainBundle] pathForResource:@"DataBase" ofType:@"plist"]; 
NSDictionary *rootDict = [[NSDictionary alloc] initWithContentsOfFile:path]; 
NSArray *allRootKeys = [rootDict allKeys]; 
NSMutableArray *mutableArray = [[NSMutableArray alloc] init]; 
for (NSString *name in allRootKeys) { 
    NSInteger index = [allRootKeys indexOfObject:name]; 
    NSDictionary *newDict = [allRootKeys objectAtIndex:index]; 
    if ([newDict valueForKey:@"Class"] == rowString) 
     [mutableArray addObject:[allRootKeys objectAtIndex:index]]; 
} 
NSArray *childControllerArray = [[NSArray alloc] initWithArray:mutableArray]; 

現在我通過childControllerArray我的下一個控制器的loadArray的ivar當與被選擇的行它獲取推一個簡單的表它顯示該數組的內容.... 當我刪除上面的代碼,並通過一個簡單的數組對象添加到其中,它工作得很好.... PLEASE HELP

給出的例外是:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSCFString 0x543eb0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key Class.

回答

0

[rootDict allKeys]; //這是NSString的陣列,NOT NSDictionarys

的陣列

此代碼不能工作

NSArray *allRootKeys = [rootDict allKeys]; 
NSDictionary *newDict = [allRootKeys objectAtIndex:index]; 
+0

它可以和工作,但存儲在newDict的值不是當然一個NSDictionary:P – rpetrich 2009-06-18 08:17:58