Question

I am trying to load xml data using newTBXMLWithURL method and once success block returns xml, I am trying to dispatch it using delegation so that controller receives NSMutableArray of records but I must be doing something wrong and I get an error in console that says "PROGRAM RECEIVED EXC_BAD_ACCESS" I am not sure where I have gone wrong. Code attached below

#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

Input sample:

<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>
Was it helpful?

Solution

Thanks for letting us know the actual error message. There is no a single reason for that error or warning.

Also, are you using ARC or just forgot to autorelease the stuff? Which Xcode version and compiler are you using? All these details matter.

I'd say you can fix this avoiding self inside the block:

__block id _self = self;
TBXMLSuccessBlock s = ^(TBXML *tbxml) {
    /* use _self inside the block, not self */
};

See https://stackoverflow.com/a/7854315/143097.

Previous answer:

It seems you're calling a method that doesn't exist: newTBXMLWithURL:success:failure:. At least in my version of TBXML it is called: tbxmlWithURL:success:failure:.

I bet there is a hint about this somewhere in the error message, isn't it?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top