简体   繁体   English

UIViewController.storyboard 必须仅在主线程中使用 - 新错误我不知道如何修复?

[英]UIViewController.storyboard must be used from main thread only - New Error I don't know how to fix?

After a users authentication is confirmed, instead of transitioning to home storyboard like I tell it to it keeps crashing, why is this and how can I fix this?确认用户身份验证后,而不是像我告诉它的那样转换到家庭 storyboard 不断崩溃,这是为什么,我该如何解决?

let confirmAction = UIAlertAction(title: "Pay", style: .default) { (action) in
        do {
            let context: LAContext = LAContext()
            if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil) {
                context.evaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, localizedReason: "Please confirm it's you") { (good, error) in
                    if good {
                        let homeViewController = self.storyboard?.instantiateViewController(identifier: Constants.Storyboard.homeViewController) as? HomeViewController
                        self.view.window?.rootViewController = homeViewController
                        self.view.window?.makeKeyAndVisible()
                    } else {
                        
                    }
                }
            }
        }
    }
    let cancelAction = UIAlertAction(title: "Cancel", style: .destructive, handler: nil)
    let number = moneyTextField.text
    D_AlertController.showAlert(style: .alert, title: "Confirm", message: "Pay Robyn 
    Saunders $\(number!)?", actions: [cancelAction, confirmAction], completion: nil)

Wrap it inside把它包在里面

DispatchQueue.main.async {
    let homeViewController = self.storyboard?.instantiateViewController(identifier: Constants.Storyboard.homeViewController) as? HomeViewController
    self.view.window?.rootViewController = homeViewController
    self.view.window?.makeKeyAndVisible()
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 UIViewController.navigationController 只能在主线程中使用 - UIViewController.navigationController must be used from main thread only ImageView 只能在主线程中使用 - ImageView must be used from main thread only 使用Storyboard Refrences时如何显示新的UIViewController - How do I present a new UIViewController when Storyboard Refrences are used UIApplication 委托只能在主线程中使用 - Swift - UIApplication delegate must be used from main thread only - Swift iOS:只能从主线程使用UIWindow.rootViewController - iOS: UIWindow.rootViewController must be used from main thread only UIDatePicker setEnabled必须仅在主线程中使用 - UIDatePicker setEnabled must be used from main thread only WARNING-[UIApplication delegate] 只能在主线程中使用 - WARNING-[UIApplication delegate] must be used from main thread only UIImagePickerController 只能在主线程中使用 | 应用崩溃 - UIImagePickerController must be used from main thread only | app crash UIApplication.keywindow,只能从主线程使用警告 - UIApplication.keywindow ,must be used from main thread only warning Swift错误“ UIButton.currentTitle必须仅在主线程中使用” - Swift Error “UIButton.currentTitle must be used from main thread only”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM