Xcodian Solangi
Xcodian Solangi

Reputation: 2408

UIAlertViewcontroller is not being popped before going to viewcontroller

I want after signup the alert controller should pop up and then go the loginFirstViewController but this is not going to happen why?? it only goes to loginfirstviewcontroller instead of poping up alert 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)

                }

Upvotes: 1

Views: 117

Answers (1)

abdullahselek
abdullahselek

Reputation: 8473

You directly opened new viewcontroller to prevent this you should add completion handler for uialertaction. When the user press ok button you can open other 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)

Upvotes: 3

Related Questions