NSUnknownKeyException,KVC合规性代码无效

时间:2009-06-18 07:10:20

标签: objective-c cocoa key-value-coding

下面这段代码成功构建并且对我来说似乎没有问题但是不起作用...请注意我是关键值编码的新手,我们将非常感谢您的帮助...... 在表视图委托didSelectRowAtIndexPath:方法 categoriesList是一个包含5个条目的简单表

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,当使用特定数组选择任何行时它会被推送,并显示该数组的内容.... 当我删除上面的代码并传递一个简单的对象数组,它工作得很好.... 请帮助

给出的例外是:

  

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

1 个答案:

答案 0 :(得分:0)

[rootDict allKeys]; //这是NSStrings的数组,不是NSDictionarys的数组

此代码无效

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