我想presentViewController但崩潰與下面的堆棧跟蹤。 有人可以檢查和幫助。呈現視圖控制器時崩潰
代碼以presentViewController
func moveToChatView(){
SwiftSpinner.show(Strings.loading)
let destViewController:GroupChatViewController = UIStoryboard(name: "GroupChat", bundle: nil).instantiateViewControllerWithIdentifier("GroupChatViewController") as! GroupChatViewController
destViewController.currentRiderRideID = self.riderRideId!
if NSThread.isMainThread() == true{
self.presentViewController(destViewController, animated: true, completion: nil)
}else{
dispatch_sync(dispatch_get_main_queue()){
self.presentViewController(destViewController, animated: true, completion: nil)
}
}
}
致命異常:NSRangeException 0的CoreFoundation 0x182b482d8 exceptionPreprocess 1 libobjc.A.dylib 0x1948140e4 objc_exception_throw 2的CoreFoundation 0x182a2f4c0 CFStringConvertNSStringEncodingToEncoding 3的UIKit 0x1879e01b4 - [UINib instantiateWithOwner:選項:] 4 UIKit 0x1878dc318 - [UIViewController _loadViewFromNibNamed:bundle:] 5 UIKit 0x1875c09bc - [UIViewController loadVi ewIfRequired] 6的UIKit 0x1875c0928 - [UIViewController的視圖] 7的UIKit 0x187cb618c - [_ UIFullscreenPresentationController _setPresentedViewController:] 8的UIKit 0x1878c60dc - [UIPresentationController initWithPresentedViewController:presentingViewController:] 9的UIKit 0x1878e2378 - [UIViewController中_presentViewController:withAnimationController:完成:] 10的UIKit 0x1808e8c8 __62- [UIViewController presentViewController:animated:completion:] _ block_invoke 11 UIKit 0x1876ae0ec - [UIViewController presentViewController:animated:completion:] 12 Quickride 0x100451968部分適用於LiveRideMapViewController。(moveToChatView() - >())。(closure#1 )(LiveRideMapViewController.swift:1868) 13 libdispatch.dylib 0x194e91954 _dispatch_client_callout 14 libdispatch.dylib 0x194e9f590 _dispatch_barrier_sync_f_slow_invoke 15 libdispatch.dylib 0x194e91954 _dispatch_client_callout 16 libdispatch.dylib 0x194e9620c _dispatch_main_queue_callback_4CF 17的CoreFoundation 0x182aff7f8 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE 18的CoreFoundation 0x182afd8a0 __CFRunLoopRun 19的CoreFoundation 0x182a292d4 CFRunLoopRunSpecific 20 GraphicsServices 0x18c47f6fc GSEventRunModal 21的UIKit 0x187626f40 UIApplicationMain 22 Quickride 0x100259a70 main(AppDelegate.swift:23) 23 libdyld.dylib 0x194ebea08 start
是你確定'GroupChatViewController'在你的故事板'GroupChat'裏面,而不在'xib'裏面? –
您可以放下一個斷點並告訴我們哪一行特別引起異常? – Erik
是的,當試圖呈現GroupChatViewController我驗證線程是否在主線程中,在這個流程中,它在後臺線程,所以它去了別的塊,一旦進入dispatch_sync(dispatch_get_main_queue())self.presentViewController(destViewController,動畫:真,完成:無) }它崩潰了,是因爲當前視圖控制器不可用 –