不同线程上的 RSS 不起作用,但在主线程上工作正常
我试图在我的 iPhone 应用程序中的不同线程上获取 rss 解析器,但是当我这样做时,我只得到旋转指示器(即什么也没有)。但是,如果我注释掉 viewDidAppear 中的调用 [NSThread....],并取消注释行 [self loadData],则一切正常(但它不在不同的线程上)。我错过了什么吗?感谢您可以在这里提供的任何见解!
这是代码。
- (void)viewDidAppear:(BOOL)animated {
[NSThread detachNewThreadSelector:@selector(loadData) toTarget:self withObject:nil];
//[self loadData];
[super viewDidAppear:animated];
}
- (void)loadData {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
if (items == nil) {
[activityIndicator startAnimating];
Parser *rssParser = [[Parser alloc] init];
[rssParser parseRssFeed:@"http://www.mywebsite.com/xml" withDelegate:self];
[rssParser release];
} else {
[self.tableView reloadData];
}
[pool release];
}
I'm trying to get an rss parser on a different thread in my iphone app, but when I do this I only get the spinning indicator (i.e., nothing). But if I comment out the call [NSThread....] in viewDidAppear, and uncomment the line [self loadData], everything works (but then its not on a different thread). Am I missing something? Thanks for any insight you can provide here!!
Here is the code.
- (void)viewDidAppear:(BOOL)animated {
[NSThread detachNewThreadSelector:@selector(loadData) toTarget:self withObject:nil];
//[self loadData];
[super viewDidAppear:animated];
}
- (void)loadData {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
if (items == nil) {
[activityIndicator startAnimating];
Parser *rssParser = [[Parser alloc] init];
[rssParser parseRssFeed:@"http://www.mywebsite.com/xml" withDelegate:self];
[rssParser release];
} else {
[self.tableView reloadData];
}
[pool release];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所有 UI 更改都应在主线程上进行:
检查
items
是否为 null,如果是,则开始为指示器设置动画,然后然后启动新线程。All UI changes should be made on the main thread:
Check if
items
is null, if it is, start animating the indicator and then start the new thread.