我有一个应用程序需要从网络加载来自Internet的UITableView的数据。但是,这会延迟视图控制器的加载。有任何想法吗?
答案 0 :(得分:1)
您应该使用线程来执行长时间运行的任务。你现在不在吗?
答案 1 :(得分:0)
尝试:
#pragma mark -
#pragma mark Helpers
#pragma mark -
- (void)load
{
[NSThread sleepForTimeInterval:4.0];
self.results = [NSArray arrayWithObjects:@"Canada", @"England", @"France", @"Spain", nil];
[self.view performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
}
#pragma mark -
#pragma mark Main
#pragma mark -
- (void)viewDidLoad
{
[super viewDidLoad];
NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
[queue addOperation:[[[NSInvocationOperation alloc] initWithTarget:self selector:@selector(load) object:nil] autorelease]];
}