我尝试使用newTBXMLWithURL方法加载xml数据,一旦成功块返回xml,我尝试使用委托来分派它,以便控制器接收记录的NSMutableArray,但我一定是做错了什么,我在控制台中得到一个错误,说"PROGRAM NSMutableArray EXC_BAD_ACCESS“,我不确定哪里出错了。下面附加的代码
#import "XmlParser.h"
#import "TBXML+HTTP.h"
#import "NewsObject.h"
@implementation XmlParser
@synthesize delegate = _delegate;
- (void)GetNewsList
{
TBXMLSuccessBlock s = ^(TBXML *tbxml) {
NSMutableArray *arrayOfNews;
TBXMLElement *root = tbxml.rootXMLElement;
TBXMLElement *newsListElement = [TBXML childElementNamed:@"NewsList" parentElement:root];
TBXMLElement *newsElement = [TBXML childElementNamed:@"News" parentElement:newsListElement];
while(newsElement !=nil){
NewsObject *news = [[NewsObject alloc]init];
news.headLine = [TBXML textForElement: newsElement ->firstChild];
news.description = [TBXML textForElement:newsElement ->firstChild->nextSibling];
news.imageUrl = [TBXML textForElement:newsElement->firstChild->nextSibling->nextSibling];
if(arrayOfNews==nil)
arrayOfNews = [NSMutableArray arrayWithObject:news];
else
[arrayOfNews addObject:news];
newsElement = newsElement ->nextSibling;
}
[self.delegate XmlParser:self feedReady:arrayOfNews];
};
TBXMLFailureBlock f = ^(TBXML *tbxml, NSError *error) {
NSLog(@"nay");
};
[TBXML newTBXMLWithURL:[NSURL URLWithString:@"url"]
success: s
failure: f];
}
@end输入示例:
<xmlData>
<NewsList>
<News newsId="1" providerId="1" articleId="95020" sportId="6" sportName="RBL">
<Headline>Matai signs on with Manly</Headline>
<Description>
Manly has retained another one of its premiership stars with Steve Matai committing to the Sea Eagles until the end of the 2015 season.
</Description>
<Image>
http:google.com/All.png
</Image>
</News>
<News newsId="2" providerId="1" articleId="95019" sportId="7" sportName="RBU">
<Headline>Reds lose Lucas for Brumbies clash</Headline>
<Description>
Queensland has lost key utility back Ben Lucas to injury on the eve of Saturday night's vital match with the Brumbies at Canberra Stadium.
</Description>
<Image>
http:google.com/All.png
</Image>
</News>
</NewsList>
<xmlData>发布于 2012-05-27 18:26:31
感谢您让我们知道实际的错误消息。该错误或警告没有单一的原因。
另外,你是在使用ARC,还是忘了自动释放呢?您使用的是哪个Xcode版本和编译器?所有这些细节都很重要。
我想说你可以避免在代码块中使用self来解决这个问题:
__block id _self = self;
TBXMLSuccessBlock s = ^(TBXML *tbxml) {
/* use _self inside the block, not self */
};参见https://stackoverflow.com/a/7854315/143097。
上一个答案:
您似乎正在调用一个不存在的方法:newTBXMLWithURL:success:failure:。至少在我的TBXML版本中,它被称为:tbxmlWithURL:success:failure:。
我敢打赌,在错误消息中的某个地方有关于这一点的提示,不是吗?
https://stackoverflow.com/questions/10773155
复制相似问题