Objective-C“RootViewController”可能不会响应“-parseXMLFileAtURL:” xCode 中的错误

发布于 2024-09-28 19:26:38 字数 1557 浏览 3 评论 0原文

在 xCode 中构建和运行我的项目时出现此错误: RootViewController 可能无法响应 -parseXMLFileAtURL: 我正在尝试根据以下教程开发基本的 Apple RSS 阅读器:

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

我发生此错误的代码部分如下所示:

- (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); 
}

任何人都可以吗解释一下为什么这个 parseXMLFileAtURL 命令让人如此心痛?

谢谢

更新***

我还在同一个文件中定义了 parseXMLFileAtURL ;但是,我将这部分代码放在了 viewDidAppear 方法之后(我的错)。因此,当我更改方法的顺序时,错误就会消失。但是当我这样做时,我收到另一个错误,也许你们也可以帮助解决这个错误!这里是:

没有实现 NSXMLParserDelegate 协议

RootViewController在这段代码中

- (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];
}

:错误发生在以下行之后:[rssParser setDelegate:self];< /code> - 这可能有什么问题?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

北城孤痞 2024-10-05 19:26:38

关于您的第二个问题, RootViewController 不符合 NSXMLParserDelegate 协议。只需将其添加到您的 RootViewController.h 文件中即可:

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

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> { .....
百变从容 2024-10-05 19:26:38

愚蠢的问题:您的 RootViewcontroller 类是否定义了名为 -parseXMLFileAtURL: 的方法?如果 -parseXMLFileAtURL: 出现在调用它的方法之后,您还需要在标头中声明它。

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.

暗喜 2024-10-05 19:26:38

确保您在 RootViewController.m 中定义了 parseXMLFileAtURL

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

并确保在标头中将其定义为:

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

另外,请确保当您尝试从以下位置获取内容时在网络上,您使用的是 NSURL,而不是 NSString。您可以通过以下方式使用字符串实例化 NSURL:

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

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://..."];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文