【发布时间】:2011-11-05 22:43:04
【问题描述】:
我的程序中有这个简单的循环:
for (Element *e in items)
{
NSDictionary *article = [[NSDictionary alloc] init];
NSLog([[e selectElement: @"title"] contentsText]);
[article setValue: [[e selectElement: @"title"] contentsText] forKey: @"Title"];
[self.articles insertObject: article atIndex: [self.articles count]];
[article release];
}
它使用 ElementParser 库从 RSS 提要中创建一个值字典(除了“标题”之外还有其他值,我已经省略了)。 self.articles 是一个 NSMutableArray,用于存储 RSS 文档中的所有字典。
最后,这应该生成一个字典数组,每个字典都包含我需要的关于任何数组索引处的项目的信息。当我尝试使用 setValue:forKey: 它给了我
this class is not key value coding-compliant for the key "Title"
错误。这与 Interface Builder 无关,它只是代码。为什么会出现此错误?
【问题讨论】:
-
有什么理由不使用
-setObject:forKey:,规范的NSMutableDictionary方法来添加/替换字典中的对象? -
当我使用它时,我得到
[__NSDictionary0 setObject:forKey:]: unrecognized selector sent to instance 0x4e7efb0'
标签: objective-c data-structures nsdictionary