計算用のバックグラウンド スレッドと 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)
}
}
}