1
我如何在一個線程中啓動另一個viewcontroller?NSThread presentviewcontroller調用?
我的代碼不起作用:
- (IBAction)btnGotoNextVC:(id)sender
{
[self.isLoading startAnimating];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[NSThread detachNewThreadSelector:@selector(gotoSecondController:)
toTarget:self
withObject:[NSArray arrayWithObjects:@"hello there", nil]];
}
和我的線程:
- (void) gotoSecondController: (NSArray*) parameters
{
NSString* data1 = parameters[0];
NSLog(@"%@", parameters[0]);
ViewController2 *VC2 = [self.storyboard instantiateViewControllerWithIdentifier:@"myView2"];
VC2.global_myLabel = [NSString stringWithFormat:@"Hallo %@", data1];
[self presentViewController:VC2 animated:YES completion:nil];
}
它是由該行崩潰:
[self presentViewController:VC2 animated:YES completion:nil];
錯誤是:
-[NSStringDrawingContext animationDidStart:]: unrecognized selector sent to instance 0x8f983c0
我能做些什麼?感謝您的回答!
謝謝您的回答! 但我有一個的UITableView和我從網頁獲得源代碼,並解析它。 現在,當我調用從頁面讀取源代碼的函數時,UI會出現問題。我怎樣才能解決這個問題? 第一控制器stucks當我點擊按鈕和閱讀網站代碼.. 然而,感謝您的快速答覆。 – user3032152
我想這取決於是什麼讓它吸...你是加載或解析主線程上的所有HTML?這會把事情搞定。你可以在一個單獨的線程上創建並傳遞數據給一個UIViewController,然後將它顯示在主線程中,這對你有用嗎?請注意,我不確定您是否可以在單獨的線程上更改標籤文本,因此您必須在後臺線程中處理該標籤文本,然後更新主線程上的標籤 – cjwirth