I've had similar problems in the past with UIAlertController
in the sense that there's always a lag on the UI thread after the UIAlertController
is dismissed.
My problem right now is that I want to perform a segue if the user clicks on the "Okay" UIAlertAction
and nothing happens if "Cancel" UIAlertAction
is pressed.
This is my code:
// create the uialertcontroller to display
let alert = UIAlertController(title: "Do you need help?",
message: "Would you like to look for a consultant?",
preferredStyle: .alert)
// add buttons
let okay = UIAlertAction(title: "Yes, please.", style: .default, handler: {_ in
self.performSegue(withIdentifier: "segue", sender: nil)
})
let no = UIAlertAction(title: "No, I'm okay.", style: .cancel, handler: nil)
alert.addAction(okay)
alert.addAction(no)
self.present(alert, animated: true, completion: nil)
What is currently happening is when I tap "Okay" the segue is performing, but I can only see the last moments of the transition (i.e the animation starts while the UIAlertController
is being dismissed).
How do I make the segue start once the UIAlertController
is dismissed?
Note - I prefer not solving this in a hacky method like performing the segue after a fixed delay if there's another way.
Thanks!