开发者

How to resolve 'RootViewController' may not respond to '-parseXMLFileAtURL:' in Xcode 3.2.3

I'm making a simple RSS feed iPhone app, and I run into this:

- (void)viewDidAppear:(BOOL)animated
{
   开发者_StackOverflow [super viewDidAppear:animated];

    if ([stories count] == 0)
    {
        NSString * path = @"myfeedURL.rss";
        [self parseXMLFileAtURL:path]; <-------Error Here
    }
}


The method is defined after it is used. The Objective-C compiler is one-pass, so it doesn't have the declaration for parseXMLFileAtURL: yet. I present three ways of fixing this:

Define it before it is used:

-(void)parseXMLFileAtURL:(...)... {
  ...
}

-(void)viewDidAppear:(BOOL)animated {
  ...
}

Stick in your header:

@interface RootViewController ...
...

-(void)parseXMLFileAtURL:(...)...;

@end

Or stick it in a "class continuation":

@interface RootViewController()
-(void)parseXMLFileAtURL:(...)...;
@end

@implementation RootViewController
...

Class continuations are useful for things like "private" methods/properties and protocols — you can do @interface Foo()<BarDelegate> to avoid header spaghetti.

EDIT: And the name of the method suggests that it takes an NSURL*, but you're passing an NSString*. I would either change it to say "URLString" or make it take an NSURL*.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜