0

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.

2 Answers 2

3

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.

unwind segue

Now your button should return you to the Primary View Controller.

1

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

2
  • Hmm, that works, but there is a problem. I need to have Top Bar on in the Navigation Controller to get the Navigation Bar in the Table View Controllers and onwards, BUT I don't want to see it on the Primary View Controller which has its own custom layout. Turning Top Bar off in the view settings doesn't hide it for that screen. Nov 19, 2012 at 23:01
  • I think in that case you could call [self.navigationController setNavigationBarHidden:YES animated:NO]; in viewWilAppear from your primary view controller if you don't want to see it there.
    – foggzilla
    Nov 19, 2012 at 23:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.