How to dismiss ViewController in Swift?
Question
I am trying to dismiss a ViewController in swift by calling dismissViewController
in an IBAction
.1
2
3
4
5
6
7
8
9func cancel(sender: AnyObject) {
self.dismissViewControllerAnimated(false, completion: nil)
println("cancel")
}
func done(sender: AnyObject) {
self.dismissViewControllerAnimated(false, completion: nil)
println("done")
}
I could see the println message in console output but ViewController never gets dismissed. What could be the problem?
Answer
Using Segue
If you present the viewController by pushing, you should use below to dismiss1
navigationController.popViewControllerAnimated(true)
Using Modal
The dismiss
is used to close ViewControllers that presented using modal1
dismiss(animated: true, completion: nil)
Reference
This is the end of post