Using Swift, I am trying to dismiss a modal programmatically. I would like to use Apple's recommended technique:
When it comes time to dismiss a presented view controller, the preferred approach is to let the presenting view controller dismiss it. In other words, whenever possible, the same view controller that presented the view controller should also take responsibility for dismissing it.(1)
How do I do this with Swift? I need to set the presenting view controller as a delegate, and when a "Done" button is tapped in a modal, call a function in the presenting view controller to dismiss.
Note that I have created the modal segue in Storyboard.
In my presenting view controller, I have this function written:
func modalDismissed(){
self.dismissModalViewControllerAnimated(true)
println("Modal Dismissed")
}
I looked around, and found this SO post, but it was not entirely helpful. In addition, they set up an observer to listen for when the modal closes--not recommended. How can I detect the dismissal of a modal view controller in the parent view controller?
Note: If you downvote, please explain why