Reputation: 1048
My storyboard layout for a restaurant is such:
Primary View Controller > Navigation Controller > Table View Controller > 3 Separate Table Views
The Primary View Controller goes to several different View Controllers, so I will need to return to it regularly. The Table View Controller controls 3 separate Table Views for different menus. Having the Table View Controller in a Navigation Controller allows the Back button to get out of the 3 Separate Table Views, but I can't figure out how to get a Back button from the Table View Controller to the Primary View Controller.
So far i've done this all in the storyboard GUI, so if the fix can be sorted there it would be easiest for me to understand.
Upvotes: 0
Views: 2997
Reputation: 3861
If you don't want to put the navigation controller in front of the Primary View Controller, you could use an "unwind segue."
Create an IBAction method to execute an unwind segue inside your primary view controller:
PrimaryVC.h
- (IBAction)unwound:(UIStoryboardSegue *)segue;
PrimaryVC.m
- (IBAction)unwound:(UIStoryboardSegue *)segue
{
// No need to do anything here...
}
In the first Table View Controller, drag a bar button item to the top left side of the navigation item (bar). Once it's there, hold the control key and drag down from the bar button to the bottom of the scene where you'll see a green exit icon. The unwound:
method should show up in a list... select that method.
Now your button should return you to the Primary View Controller.
Upvotes: 3
Reputation: 1725
Why not put your navigation controller as part of your primary view controller? Then when you push the table view controller you'd get a back button on it. So it would be Navigation Controller -> Primary View Controller ->Table View Controller -> ...
I have done this with storyboards in that the navigation controller scene is first, then the relationship with the root view controller is the primary view controller
Upvotes: 1