Using storyboards, what is the proper way to dismiss a modal?
- using IBAction and writing code to dismiss after a button click?
- using segue and notify the parent view controller after a button click?
Using storyboards, what is the proper way to dismiss a modal?
See Here Dismissing a Presented View Controller about halfway down
So you should use an IBAction and writing code to dismiss after a button click
I've found that usually when I'm attempting to do this in storyboard I'd rather not create extra classes. It still makes sense to perform the dismiss from the presenting view controller, so that requires a class to back it.
If you create an IBAction in the presenting view controller and name it appropriately e.g.
Then from storyboard wherever you want to trigger the dismiss from you create an action to the first responder as shown below. You can extend this to work with multiple presenting view controllers by creating unique names for the IBActions.
More information on first responder and the responder chain
According Alex Cio answer for
Swift 3
andXCode 8.3
:Create class:
But in storyboard you should choose:
Only after this option appear on
Action Segue
menuTo do this inside the
UIStoryboard
you need first to create an Object of the typeUIStoryboardSegue
in your projectThen insert following method inside the class. Here is my class
@implementation DismissController
Now you can use it inside your
UIStoryboard
. Select the button that should make theUIViewController
Disappear and drag it to theUIViewController
you want to go to. In my case it shows **dismiss Controller* because of the name of my Class.Select it and you are done! There is also a very good explanation on this website.
See my answer here. It gives you two ways to dismiss the modal view controller with storyboard. I like method two described because one you add the class in your project your return from modal views can be done with no code using storyboard alone. That said, if you have implemented a delegate and delegate protocol, it is also a good place to put the dismissModalViewController statement.
As the Apple online documentation indicates, the presenting view controller is responsible for dismissing the modal (presented) view.
There's a post and example available here