ios - UIAlertViewcontroller 在转到 viewcontroller 之前没有被弹出

标签 ios swift xcode

我希望在注册后弹出警报 Controller ,然后进入 loginFirstViewController 但这不会发生,为什么?它只会转到 loginfirstviewcontroller 而不是弹出警报 Controller

     if error == nil {



                FIRAuth.auth()?.currentUser!.sendEmailVerification(completion: { (error) in
                })



                print("You have successfully signed up")
                //Goes to the Setup page which lets the user take a photo for their profile picture and also chose a username




                let alertController = UIAlertController(title: "Successful!", message: "Email Verification link sent", preferredStyle: .alert)


                let alertActionOkay = UIAlertAction(title: "Okay", style: .default)

                    let vc = self.storyboard?.instantiateViewController(withIdentifier: "LoginFirstViewController")

                    self.present(vc!, animated: true, completion: nil)



                  alertController.addAction(alertActionOkay)

               self.present(alertController, animated: true, completion: nil)

                }

最佳答案

您直接打开了新的 View Controller 以防止出现这种情况,您应该为 uialertaction 添加完成处理程序。当用户按下确定按钮时,您可以打开其他 View Controller

    let alertController = UIAlertController(title: "Successful!", message: "Email Verification link sent", preferredStyle: .alert)
    let alertActionOkay = UIAlertAction(title: "Okay", style: .default) { (action) in
        let vc = self.storyboard?.instantiateViewController(withIdentifier: "LoginFirstViewController")
        self.present(vc!, animated: true, completion: nil)
    }
    alertController.addAction(alertActionOkay)
    self.present(alertController, animated: true, completion: nil)

关于ios - UIAlertViewcontroller 在转到 viewcontroller 之前没有被弹出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43208684/

相关文章:

Xcode - 无法采用协议(protocol)

ios - [Swift]加载运行时下载的 scn 文件时为 nil

ios - 编辑 PHAssets 时如何保留原始照片元数据?

ios - 无法从 AppDelegate 中实例化 rootViewController

swift - 将 Google map 添加到 Swift 中的 View

ios - 解析本地json文件到对象

ios - Xcode - 查看屏幕尺寸

ios - Swift - 在 Tic Tac Toe 中编写 Tie 函数

iOS swift UICollectionviewcell 快照错误

ios - ObjectMapper 因根元素而失败