簡體   English   中英

介紹ViewController時崩潰

[英]Crash when presenting viewcontroller

我正在嘗試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:束:] 5的UIKit 0x1875c09bc - [UIViewController中loadViewIfRequired] 6 UIKit 0x1875c0928-[UIViewController視圖] 7 UIKit 0x187cb618c-[_ UIFullscreenPresentationController _setPresentedViewController:] 8 UIKit 0x1878c60dc-[UIPresentationController initWithPresentedViewController:presentingViewController:] 9 UIKit 0x1878e2present-[UIViewController:]動畫:完成:] _ block_invoke 11 UIKit 0x1876ae0ec-[UIViewController presentViewController:動畫:完成:] 12 Quickride 0x100451968部分申請LiveRideMapViewController。(moveToChatView () - >())(閉合#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 0x194

作為一個規則不使用DISPATCH- 同步 ,而是使用DISPATCH- 異步和你沒有,如果你檢查主線程上,如果它是一個UI操作有一個機會,這將是上一回線剛將dispatch_ async同步到主隊列,它將在主隊列的下一個運行循環上執行UI操作,並且UI將“平滑”,請嘗試以下操作:

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)
   }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM