Reputation: 2196
I have a main menu screen in my app, so that when i hit a button i push to another view controller. In one of these view controllers i use a tap gesture recognizer to to a modal view, and again to dismiss the modal view. But in this modal view I want a button {main menu} to dismiss the view controller and then dismiss a push.
How can i dismiss 2 layers of push and modal views. With a push segue do you dismiss the push view, or simply just add another push to go back. Right now i can't dismiss the modal and push with that 1 button (thats on the modal screen).
Some advice would be helpful..
Edit: main menu view controller ->(push segue)-> view controllerXXX view controllerXXX ->(modal segue)-> pause controller pause controller ->(dismiss modal segue)-> view controllerXXX pause controller ->(???(will have to dismiss modal and pop push)???)-> main menu view controller
Upvotes: 2
Views: 1383
Reputation: 12663
You should use delegation to make a callback from the modal view controller to the parent view controller that presented it, which can then dismiss the modal and pop itself off the navigation stack.
If you're not familiar with the delegation pattern, see Apple's introduction on it:
You can also try this tutorial from Ray Wenderlich's site on beginning storyboards (which also has an example in it of using delegation):
http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1
Edit:
Here's how you dismiss a modal view controler from the presenting view controller (that is, self is a view controller who presented the modal):
[self dismissModalViewControllerAnimated:YES];
Here's how you pop a view controller off a navigation stack (where self is the view controller you want to pop):
[self.navigationController popViewControllerAnimated:YES];
See the Wenderlich tutorial (go through all of it, there's 2 parts), it will show you how to create a protocol and call a delegate's method.
No, it's not mentioned by the name "delegation" in Wenderlich's tutorial... this is the name of the design pattern.
Upvotes: 3