【问题标题】:TBXML block iOSTBXML 阻止 iOS
【发布时间】:2012-05-27 10:10:20
【问题描述】:

我正在尝试使用 newTBXMLWithURL 方法加载 xml 数据,一旦成功块返回 xml,我正在尝试使用委托调度它,以便控制器接收 NSMutableArray 的记录,但我一定做错了,我得到了控制台中显示“PROGRAM RECEIVED 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>

【问题讨论】:

    标签: ios tbxml


    【解决方案1】:

    感谢您告知我们实际的错误消息。该错误或警告没有单一原因。

    另外,您是在使用 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:

    我敢打赌,错误消息中的某处对此有提示,不是吗?

    【讨论】:

    • 我认为是新版本的 TBXML 具有 newTBXMLWithURL。正如我上面提到的错误是“EXC_BAD_ACCESS”并且控制台有这个“尝试使用不在框架中的块创建USE_BLOCK_IN_FRAME变量”我确信这与块有关,但我不知道如何去修复它。
    • 就是这样。非常感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 2013-10-17
    • 2011-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多