我想先顯示視圖,然後在後臺線程中加載數據。當我從根控制器導航到視圖控制器時,我想首先顯示視圖。截至目前,它保持在根控制器上,直到視圖控制器被加載。這是我的根控制器的代碼。iPhone,後臺線程無法正常工作
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ProductDetailViewController *tempProductDetail = [[ProductDetailViewController alloc] init];
[self.navigationController pushViewController:tempProductDetail animated:YES];
[tempProductDetail release];
}
ProductDetailViewController,在這裏我要首先顯示視圖,然後加載數據...
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:YES];
[self performSelectorOnMainThread:@selector(workerThread) withObject:nil waitUntilDone:NO];
}
-(void) workerThread{
NSAutoreleasePool *arPool = [[NSAutoreleasePool alloc] init];
[arPool release];
}
不知道我做錯了什麼。請幫忙。
performSelectorOnMainThread不創建一個新的thread.detachNewThreadSelector將創建一個新的線程。 – rckoenes 2011-04-27 12:43:28
這樣做 \t [NSThread detachNewThreadSelector:@selector(workerThread)toTarget:self withObject:nil]; 顯示我一個錯誤..... bool _WebTryThreadLock(布爾),0x664e200:試圖從主線程或Web線程以外的線程獲取Web鎖。這可能是從輔助線程調用UIKit的結果。現在崩潰... – donito 2011-04-27 13:55:04