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