NSUnknownKeyException',原因:'[ setValue:forUndefinedKey:]

发布于 2024-11-03 19:06:32 字数 1727 浏览 3 评论 0原文

我正在尝试解析 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

魔法唧唧 2024-11-10 19:06:32

试试这个,应该可以用,我也遇到了同样的问题。如果存在整数值,它会崩溃。

[aBook setValue:[NSString stringWithFormat:@"%@",currentElementValue] forKey:elementName];

Try this one, it should work I was also facing same issue. It crashes in case there is integer value.

[aBook setValue:[NSString stringWithFormat:@"%@",currentElementValue] forKey:elementName];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文