提问者:小点点

在IOS中调用另一个屏幕时出现异常


我是IOS开发的新手。在Main. storyoard中,我添加了一个新的view控制器,将其分配给一个新的类LoginViewController并提供了一个故事板-IDloginview。在LoginViewController类中,成功登录后,我尝试以下代码调用默认的故事板视图控制器-IDwebview

NSString *storyboardName = @"Main";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"webview"];
[self presentViewController:vc animated:YES completion:nil];

在调试期间,我得到了以下异常

2016-05-04 18:37:11.020 GCM example[2690:86862]bool _ WebTryThreadLock(bool),0x7fa5d3f3d840:试图从主线程或web线程以外的线程获取web锁。这可能是从辅助线程调用UIKit的结果。现在崩溃...1 0x 11328d 34 b web thread lock 2 0x 10 e 5547 DD-[ui webview _ webviewconinitwithwebview:scalesPageToFit:]3 0x 10 e 555179-[ui webview initwith coder:]4 0x 10 e 7 b 5822 uinibdecoderdecodeobjectfor value 5 0x 10 e 7 b 5558-[uinibdecodecodeobjectforkey:]6 0x 10 e 5e 1483-[UIRuntimeConnection initwith coder:]7 0x 10 e 7 b 5822 uinibdecoderobjectforkey 20 0x 10d 065 eed 34-[loginview controller BTN sign _ in:]_ BLOCK _ invoke 21 0x 10 FD 3 F6 b5 _ _ 75-[_ _ NSURLSessionLocal taskForClass:request:uploadFile:body data:completion:]_ BLOCK _ invoke 22 0x 10 FD 51 A 02 _ _ 49-[_ _ NSCFLocalSessionTask _ task _ on queue _ did finish]_ BLOCK _ invoke 23 0x 10 D1 DC 304 _ _ nsblock operation _ IS _ CALLING _ OUT _ TO _ A _ BLOCK

有谁知道这里的错误是什么?请帮忙。


共3个答案

匿名用户

试试下面的代码,而不是你的。问题似乎是您正在从为登录服务创建的不同踏面执行UI操作。但是建议在主线程上执行UI操作

dispatch_async(dispatch_get_main_queue(), ^{
NSString *storyboardName = @"Main";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"webview"];
[self presentViewController:vc animated:YES completion:nil];
});

匿名用户

您正在辅助线程而不是< code >主线程上执行当前操作。所有的UI操作必须只能在主线程上执行,否则不会生效。

要在主线程上执行某些操作,请使用在主线程上执行的以下dispatch_async块。

dispatch_async(dispatch_get_main_queue(), ^{
    NSString *storyboardName = @"Main";
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
    UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"webview"];
    [self presentViewController:vc animated:YES completion:nil];
});

匿名用户

试试这个

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MyNetworkStoryboard" bundle:nil];
MyNetworkTableViewController *myVC = (MyNetworkTableViewController *)[storyboard instantiateViewControllerWithIdentifier:@"networkController"];
UIViewController *frontViewController = myVC;
[self.navigationController pushViewController:frontViewController animated:YES];