我有一个视图控制器是UIViewController的子类,它具有表视图,表视图中的每一行都链接到不同的xml url。我做了一个解析器类是子类的NSOperation和实现的方法来解析每行作为选择的XML文件,线程是否会干扰程序的正常工作行为?
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[self performSelectorOnMainThread:@selector(pushView) withObject:nil waitUntilDone:NO];
[self performSelectorInBackground:@selector(parseOperation:) withObject:indexPath];
}
-(void)pushView{
detailView = [[viewDetailsController alloc] initWithNibName:@"viewDetailsController" bundle:nil];
[self.navigationController pushViewController:detailView animated:YES];
}
-(void)parseOperation:(NSIndexPath *)indexPath{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
self.queue = [[NSOperationQueue alloc] init];
parserClass *parser = [[parserClass alloc] initWithParseUrl:[[self.arrayOfUrls objectAtIndex:indexPath.row]delegate:self];
[queue addOperation:parser];
[parser release];
[pool release];
}
分析器的伟大工程,但在其自定义的委托方法我称之为推视图控制器导航控制器堆栈的顶部,视图控制器正确初始化,但新视图控制器未被压入屏幕。 我不知道为什么这不起作用。
那么,是不是错了已经在后台调用线程分析器。我想我已经做了相同的事情,在后台线程解析器的同时,在主线程上调用了视图推送器。 – Sandeep 2011-05-23 11:14:04
@Core:解析器应该可以在后台线程上运行,所以它在解析时不会锁定用户界面。但是您必须使用'performSelectorOnMainThread:withObject:waitUntilDone:'从其委托方法调用主线程上的选择器来更新用户界面。 – Anomie 2011-05-23 14:27:35