performSegueWithIdentifier very slow when segue is modal

后端 未结 8 1754
天命终不由人
天命终不由人 2020-12-01 04:58

I have a simple table view where I handle the select action on the table view. This action follows a segue.

If the segue is a push segue, the next view

8条回答
  •  萌比男神i
    2020-12-01 05:48

    For developers organizing their code through subclassing, I've come to quite simple a solution I'd like to share (Swift 4):

    import UIKit
    
    class ABCViewController: UIViewController {
    
      // ... Other useful methods like overriding deinit and didReceiveMemoryWarning
    
      // Performs a segue on the main thread to ensure it will 
      // transition once a UI-slot is available
      func performSegueOnMainThread(with identifier: String, sender: Any?) {
        DispatchQueue.main.async {
          self.performSegue(with: identifier, sender: sender)
        }
      }
    }
    

    Then, simply call it from your implementation:

    myViewController.performSegueOnMainThread(with: "ShowDetailsSegue", sender: self)
    

提交回复
热议问题