1
我有一個應用程序需要從網絡爲Internet上的UITableView加載數據。但是,這會延遲視圖控制器的加載。有任何想法嗎?聯網任務延遲接口
我有一個應用程序需要從網絡爲Internet上的UITableView加載數據。但是,這會延遲視圖控制器的加載。有任何想法嗎?聯網任務延遲接口
嘗試:
#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]];
}
您應該使用線程來執行長時間運行的任務。你目前不在嗎?