开发者

Objective-C 'RootViewController' may not respond to '-parseXMLFileAtURL:' error in xCode

I have this error when building and running my project in xCode: RootViewController may not respond to -parseXMLFileAtURL: I'm attempting to develop the basic Apple RSS Reader from the tutorial at:

http://gigaom.com/apple/tutorial-build-a-simple-rss-reader-for-iphone/

my section of code that this error is occurring in looks like this:

- (void)viewDidAppear:(BOOL)animated
{ 
    [super viewDidAppear:animated]; 
    if ([stories count] == 0)
    {
         NSString * path = @"http://feeds.feedburner.com/TheAppleBlog"; 
         [self parseXMLFileAtURL:path]; 
    }
    cellSize = CGSizeMake([newsTable bounds].size.width, 60); 
}

can anybody explain why this parseXMLFileAtURL command gives so much heartache?

Thanks

UPDATED***

I also define parseXMLFileAtURL in the same file; however, I placed that section of the code after the viewDidAppear method (my bad). So when I change the order of the methods that error goes away. But when I do that, I get another error, maybe you guys can help with that error too! here it is:

Class RootViewController does not implement the NSXMLParserDelegate protocol

within thi开发者_JAVA百科s section of code:

- (void)parseXMLFileAtURL:(NSString *)URL
{
    stories = [[NSMutableArray alloc] init]; 
    NSURL *xmlURL = [NSURL URLWithString:URL]; 
    rssParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL]; 
    [rssParser setDelegate:self];
    [rssParser setShouldProcessNamespaces:NO]; 
    [rssParser setShouldReportNamespacePrefixes:NO]; 
    [rssParser setShouldResolveExternalEntities:NO]; 
    [rssParser parse];
}

The error occurs after the line: [rssParser setDelegate:self]; - what might be wrong with that?


In regards to your second question that RootViewController does not conform to the NSXMLParserDelegate protocol. Just add it like this in your RootViewController.h file:

@interface  RootViewController : UIViewController <NSXMLParserDelegate> { .....


Silly question: Does your RootViewcontroller class have a method named -parseXMLFileAtURL: defined? If -parseXMLFileAtURL: comes after the method that calls it, you'll also need to declare it in your header.


Make sure you have parseXMLFileAtURL defined in your RootViewController.m

-(void)parseXMLFileAtURL:(NSString *)url
{   
    ... 
}

And make sure you have it defined in your header as:

-(void)parseXMLFileAtURL:(NSString *)url;

Also, make sure that when you try to get the contents from the web, you're using an NSURL, not an NSString. You can instantiate a NSURL with a string by:

NSURL *urlFromString = [[NSURL alloc] initWithString:@"http://..."];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜