首页 文章

呈现viewcontroller时崩溃

提问于
浏览
0

我正在尝试使用presentController,但崩溃时跟随堆栈跟踪 . 有人可以检查和帮助 .

代码到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:options:] 4 UIKit 0x1878dc318 -[UIViewController _loadViewFromNibNamed:bundle:] 5 UIKit 0x1875c09bc -[UIViewController loadViewIfRequired] 6 UIKit 0x1875c0928 -[UIViewController view] 7 UIKit 0x187cb618c -[_UIFullscreenPresentationController _setPresentedViewController:] 8 UIKit 0x1878c60dc -[UIPresentationController initWithPresentedViewController:presentingViewController:] 9 UIKit 0x1878e2378 -[UIViewController _presentViewController:withAnimationController:completion:] 10 UIKit 0x1878e48c8 __62-[UIViewController presentViewController:animated:completion:]_block_invoke 11 UIKit 0x1876ae0ec -[UIViewController presentViewController:animated:completion:] 12 Quickride 0x100451968 partial apply for 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主(AppDelegate.swift:23)23 libdyld.dylib 0x194ebea08开始

1 回答

  • 0

    通常不使用dispatch_ sync ,而是使用dispatch_ async 并且你不必检查你是否在主线程上,如果它是一个UI操作并且它有可能在一个反向线程上do dispatch_ async 到主队列,它将在主队列的下一个运行循环上执行UI操作,UI将是'smooth',试试这个:

    func moveToChatView(){
        SwiftSpinner.show(Strings.loading)
    
        let destViewController:GroupChatViewController  = UIStoryboard(name:"GroupChat", bundle:  nil).instantiateViewControllerWithIdentifier("GroupChatViewController") as!    GroupChatViewController
        destViewController.currentRiderRideID = self.riderRideId!
        dispatch_async(dispatch_get_main_queue()){
           self.presentViewController(destViewController, animated: true,completion:nil)
       }
    }
    

相关问题