Objective-C“RootViewController”可能不会响应“-parseXMLFileAtURL:” xCode 中的错误
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
关于您的第二个问题,
RootViewController
不符合NSXMLParserDelegate
协议。只需将其添加到您的RootViewController.h
文件中即可:In regards to your second question that
RootViewController
does not conform to theNSXMLParserDelegate
protocol. Just add it like this in yourRootViewController.h
file:愚蠢的问题:您的
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.确保您在
RootViewController.m
中定义了parseXMLFileAtURL
并确保在标头中将其定义为:
另外,请确保当您尝试从以下位置获取内容时在网络上,您使用的是
NSURL
,而不是NSString
。您可以通过以下方式使用字符串实例化 NSURL:Make sure you have
parseXMLFileAtURL
defined in yourRootViewController.m
And make sure you have it defined in your header as:
Also, make sure that when you try to get the contents from the web, you're using an
NSURL
, not anNSString
. You can instantiate a NSURL with a string by: