rshankar rshankar - 3 months ago 9
iOS Question

How to dismiss ViewController in Swift?

I am trying to dismiss a ViewController in swift by calling

dismissViewController
in an
IBAction


@IBAction func cancel(sender: AnyObject) {
self.dismissViewControllerAnimated(false, completion: nil)
println("cancel")
}

@IBAction func done(sender: AnyObject) {
self.dismissViewControllerAnimated(false, completion: nil)
println("done")
}


random image of a segue

I could see the println message in console output but ViewController never gets dismissed. What could be the problem?

Answer

From you image it seems like you presented the ViewController using push

You need to use

navigationController.popViewControllerAnimated(true)

The dismissViewControllerAnimated is used to close ViewControllers that presented using modal

Comments