views:

42

answers:

3

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 this 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?

+1  A: 

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.

Joshua Nozzi
Thanks for the help.
sadmicrowave
A: 

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://..."];
kodai
Nice, thanks dude, check out my OP for an updated question though.
sadmicrowave
Alright, as far as your NSURL comment goes; I tried changing my NSString string in my viewDidAppear method to what you suggested and now i get an error from the [self parseXMLFileAtURL:path] line directly underneath it. The error says "Incompatible Objective-C types 'struct NSURL *', expected 'struct NSString *' when passing argument..."
sadmicrowave
+1  A: 

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

@interface  RootViewController : UIViewController <NSXMLParserDelegate> { .....
Ciryon
in my header file I already have: @interface RootViewController : UITableViewController {//method details//}@end. why would that not already do what you are suggesting?
sadmicrowave
Yes, just add the <NSXMLParserDelegate> before the {
Ciryon
Brilliant!! that fixed the problem!! thanks alot!
sadmicrowave