How to reject a UIViewController from a UIAlertController UIAlertAction?

I would like to present the user with a simple UIAlertController with one of the parameters that starts closing the parent view controller. Here is the code I'm 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)

This has no effect. After executing the "Close View" handler, the display controller that presents the warning still exists.

I also tried self.navigationController?.dismissViewControllerAnimated(true, completion: nil)UIAlertAction in the action block, but that didn't work either.

+4
source share
2 answers

Using

self.navigationController?.popViewControllerAnimated(true)

instead

self.dismissViewControllerAnimated(true, completion: nil)

works as needed and closes the view controller, which displays a warning.

+5

presentViewController . , self.dismissViewController, , . , , self.view . view.addSubView, .

0