NSUnknownKeyException',原因:'[ setValue:forUndefinedKey:]
我正在尝试解析 xml 的标签,但我没有在表视图中检索任何值。相反,应用程序因异常而终止。这是我的代码:
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if([elementName isEqualToString:@"Table"]) {
[appDelegate.books addObject:aBook];
[aBook release];
aBook = nil;
}
else
[aBook setValue:currentElementValue forKey:elementName];//problem is here
[currentElementValue release];
currentElementValue = nil;
}
其中作为委托类的“appdelegate”对象,“Books”是委托类中的可变数组,“aBook”是“Book”类的对象,在 xml 中具有属性 n 声明的标记字符串。
帮帮我,
这是我的 xml 文件:
<pre><NewDataSet>
−
<Table>
<id>1</id>
<catname>Birthday</catname>
<iid>1</iid>
<subcatname>card1</subcatname>
−
<url>
http://www.orkutpapa.com/scraps/happy-birthday-card-2-3.jpg
</url>
</Table>
−
<Table>
<id>1</id>
<catname>Birthday</catname>
<iid>2</iid>
<subcatname>card2</subcatname>
−
<url>
http://robertpattinsonwho.com/wp-content/uploads/2009/07/twilight-birthday-card.jpg
</url>
</Table>
−
<Table>
<id>1</id>
<catname>Birthday</catname>
<iid>3</iid>
<subcatname>card3</subcatname>
−
<url>
http://www.funxite.com/media/2373-birthday-card-to-wife.jpg
</url>
</Table>
−
<Table>
</pre>
异常:
* 由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[ setValue:forUndefinedKey:]:此类与键 iid 的键值编码不兼容。” 2011-04-26 10:41:03.388 XML[631:20b] 堆栈:(
i am trying to parse the tags of xml, but i am not retrieving any value in my table view. Instead application get terminated due to exception. here is my code:
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if([elementName isEqualToString:@"Table"]) {
[appDelegate.books addObject:aBook];
[aBook release];
aBook = nil;
}
else
[aBook setValue:currentElementValue forKey:elementName];//problem is here
[currentElementValue release];
currentElementValue = nil;
}
where as 'appdelegate' object of delegate class, 'Books' is mutable array in delegate class, 'aBook' is the object of 'Book' class, having property n declared strings for tag in xml.
help me out
here is my xml file:
<pre><NewDataSet>
−
<Table>
<id>1</id>
<catname>Birthday</catname>
<iid>1</iid>
<subcatname>card1</subcatname>
−
<url>
http://www.orkutpapa.com/scraps/happy-birthday-card-2-3.jpg
</url>
</Table>
−
<Table>
<id>1</id>
<catname>Birthday</catname>
<iid>2</iid>
<subcatname>card2</subcatname>
−
<url>
http://robertpattinsonwho.com/wp-content/uploads/2009/07/twilight-birthday-card.jpg
</url>
</Table>
−
<Table>
<id>1</id>
<catname>Birthday</catname>
<iid>3</iid>
<subcatname>card3</subcatname>
−
<url>
http://www.funxite.com/media/2373-birthday-card-to-wife.jpg
</url>
</Table>
−
<Table>
</pre>
exception:
* Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key iid.'
2011-04-26 10:41:03.388 XML[631:20b] Stack: (
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个,应该可以用,我也遇到了同样的问题。如果存在整数值,它会崩溃。
Try this one, it should work I was also facing same issue. It crashes in case there is integer value.