我正在尝试展示我的" ProtectedViewController"。
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller: UIViewController = storyboard.instantiateViewController(withIdentifier: "Protected") as! ProtectedPageViewController
self.present(controller, animated: true, completion: nil)
当我尝试显示时,错误会在步骤
上弹出self.present(controller, animated: true, completion: nil)
如下面的屏幕截图:
let pvc = ProtectedPageViewController()
self.present(pvc, animated: true, completion: nil)
同样的错误。已经尝试了一切。
堆栈跟踪错误:
*** First throw call stack:
(
0 CoreFoundation 0x0000000108a2c34b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010807021e objc_exception_throw + 48
2 CoreFoundation 0x0000000108a30442 +[NSException raise:format:arguments:] + 98
3 Foundation 0x0000000107c06edd -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
4 UIKit 0x0000000109be1942 -[UIKeyboardTaskQueue waitUntilAllTasksAreFinished] + 165
5 UIKit 0x000000010934ec14 -[UIKeyboardImpl setDelegate:force:] + 1404
6 UIKit 0x0000000109776152 -[UIPeripheralHost(UIKitInternal) _reloadInputViewsForResponder:] + 981
7 UIKit 0x000000010977f95c -[UIPeripheralHost(UIKitInternal) _preserveInputViewsWithId:animated:reset:] + 498
8 UIKit 0x00000001092409b7 -[UIViewController _presentViewController:modalSourceViewController:presentationController:animationController:interactionController:completion:] + 1178
9 UIKit 0x0000000109242702 -[UIViewController _presentViewController:withAnimationController:completion:] + 4971
10 UIKit 0x00000001092456df -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 530
11 UIKit 0x00000001092451c5 -[UIViewController presentViewController:animated:completion:] + 179
12 Registration 0x0000000107a7208a _TFFC12Registration23LoginPageViewController17loginButtonTappedFPs9AnyObject_T_U_FTGSqV10Foundation4Data_GSqCSo11URLResponse_GSqPs5Error___T_ + 3482
13 Registration 0x0000000107a695fb _TTRXFo_oGSqV10Foundation4Data_oGSqCSo11URLResponse_oGSqPs5Error____XFdCb_dGSqCSo6NSData_dGSqS1__dGSqCSo7NSError___ + 203
14 CFNetwork 0x000000010b8756b0 __75-[__NSURLSessionLocal taskForClass:request:uploadFile:bodyData:completion:]_block_invoke + 19
15 CFNetwork 0x000000010b874f5c __49-[__NSCFLocalSessionTask _task_onqueue_didFinish]_block_invoke + 308
16 Foundation 0x0000000107b742cd __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 7
17 Foundation 0x0000000107b73faf -[NSBlockOperation main] + 101
18 Foundation 0x0000000107b726ac -[__NSOperationInternal _start:] + 672
19 Foundation 0x0000000107b6e5ef __NSOQSchedule_f + 201
20 libdispatch.dylib 0x000000010c2600cd _dispatch_client_callout + 8
21 libdispatch.dylib 0x000000010c23de6b _dispatch_queue_serial_drain + 236
22 libdispatch.dylib 0x000000010c23eb9f _dispatch_queue_invoke + 1073
23 libdispatch.dylib 0x000000010c2413b7 _dispatch_root_queue_drain + 720
24 libdispatch.dylib 0x000000010c24108b _dispatch_worker_thread3 + 123
25 libsystem_pthread.dylib 0x000000010c60a712 _pthread_wqthread + 1299
26 libsystem_pthread.dylib 0x000000010c60a1ed start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
请帮我找到修复方法。
提前致谢!!!
P.S。:使用iOS 10.0和Swift 3
答案 0 :(得分:1)
stacktrace在NSURLSession上下文中显示了一些内容。您是在主线程中还是从某个工作线程中呈现ViewController?
请检查从主线程执行演示文稿调用是否成功:
DispatchQueue.main.async {
// here your presentation call, e.g.
self.present(controller, animated: true, completion: nil)
}
如果没有,你应该发布完整的异常(从输出窗口)和/或更多的代码(更多的区域,你提出控制器)