我有一个按钮对象,它运行一个用于计算的后台线程和一个用于 UI 更新的主线程。毕竟完成后,我想使用 移动到另一个视图控制器performSegue(withIdentifier: "thirdViewController", sender: self),但它在dispatchQueue. 我之前用过performSegue()很多次在视图控制器之间切换,我总是可以手动控制它。相反,它几乎立即移动到下一个 ViewController,而无需先完成计算。
我尝试使用self.present(thirdViewController(), animated: true, completion: nil), 并self.navigationController?.pushViewController(thirdViewController(), animated: true)更改 ViewController 但他们只是给了我一个黑屏。
@IBAction func generateText(_ sender: Any) {
DispatchQueue.global(qos: .userInteractive).async {
//computation code
DispatchQueue.main.sync {
//update UI code
self.performSegue(withIdentifier: "Segue2", sender: self)
}
}
}
