Ios 在转到viewcontroller之前未弹出UIAlertViewcontroller

Ios 在转到viewcontroller之前未弹出UIAlertViewcontroller,ios,swift,xcode,Ios,Swift,Xcode,我想注册后,警报控制器应该弹出,然后进入loginFirstViewController,但这不会发生为什么??它只进入loginfirstviewcontroller,而不是弹出警报控制器 if error == nil { FIRAuth.auth()?.currentUser!.sendEmailVerification(completion: { (error) in })

我想注册后,警报控制器应该弹出,然后进入loginFirstViewController,但这不会发生为什么??它只进入loginfirstviewcontroller,而不是弹出警报控制器

     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)

                }

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

    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)

如果用户单击“确定”按钮或其他在显示ViewController之前在ViewController上显示alertController,则您希望导航到另一个VC。您可以尝试在“警报推送新viewController”的“OK”操作中在上一个控制器上显示警报。