0

I wrote this code so that the viewcontroller changes from loginscreenviewcontroller to otpviewcontroller.

function createAlert() {
    let alertController = UIAlertController(title: nil, message: "Please wait\n\n", preferredStyle: .alert)
    let spinnerIndicator = UIActivityIndicatorView(activityIndicatorStyle: .whiteLarge)
    spinnerIndicator.center = CGPoint(x: 135.0, y: 65.5)
    spinnerIndicator.color = UIColor.black
    spinnerIndicator.startAnimating()
    self.present(alertController, animated: true, completion: nil)
    Alamofire.request(".....").responseData { response in
       switch response.result {
           case .success:
               self.dismiss(animated: true, completion: nil)
               self.performSegue(withIdentifier: "OTPSegue", sender: self)
       }
    }
}

but it gives me an error

Attempt to present <Junkart.OTPViewController: 0x79769c80> on <UIAlertController: 0x79b5fe00> whose view is not in the window hierarchy!

alert controller does close but there is no change in view controller.

Please help.

UPADTE 2 Ok. So I am able to change to the other viewController but the alert view goes to the top before the new view controller animates and takes the whole screen.

Gaurav
  • 143
  • 1
  • 3
  • 10

2 Answers2

0

You dismiss the current view controller before present new view controller. That's wrong. Remove following line instead self.dismiss(animated: true, completion: nil)

0

Error is pretty exhaustive.

You need to dismiss alert view and then perform segue with the new view controller:

alertController.dismiss(animated: true, completion: {
    self.performSegue(withIdentifier: "OTPSegue", sender: self)
}) 
Luca Davanzo
  • 21,000
  • 15
  • 120
  • 146