I would like to present a simple UIAlertController to the user with one of the options triggering the closing of the parent view controller. Here is the code that I am using:
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Close View", style: UIAlertActionStyle.Destructive, handler: {
action in
self.dismissViewControllerAnimated(true, completion: nil)
}))
alert.addAction(UIAlertAction(title: "CANCEL", style: UIAlertActionStyle.Cancel, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
It doesn't have any effect. After executing the "Close View" handler the view controller that presents the alert is still there.
I also tried self.navigationController?.dismissViewControllerAnimated(true, completion: nil)
in the UIAlertAction action block but that didn't work either.
Using
self.navigationController?.popViewControllerAnimated(true)
instead of
self.dismissViewControllerAnimated(true, completion: nil)
works as required and closes the view controller which displays the alert.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With