1
votes

I have a storyboard with the following layout.

  1. TabBarController
  2. --> NavigationController
  3. ----> TableViewController
  4. ----> TableViewController
  5. ----> TabBarController (hides bottom bar on push)
  6. ------> TableViewContrller (set title)

I push 4 & 5 onto navigation controller 2. 5 hides bottom bar when pushed and when 6 is visible because it's tab bar item is selected the title set on the view controller 6 is not visible in the navigation bar

My question is, what is the best way to set this from interface builder (XCode5)?

I also attempted to add a navigation item to view controller 6 and set the title there but this had no effect.

Whilst writing this, I realised that view controller 6 is never pushed onto the navigation controller stack, which is why it has no navigation item. I was about to abandon the question when realising that setting the navigation item on view controller 3 produces the effect I expected. Which is to toggle navigation bar titles when changing to different tabs.

This of course is because they are completely different navigation controllers. Is there anyway to simulate this behaviour with the structure I have? If not can you suggest an alternative approach?

1
You shouldn't have a tab bar controller pushed onto navigation controller.Filip Radelic
Thanks Filip, is this bad practice or against user interface guidelines?nacross

1 Answers

5
votes

You should not have a tab bar controller pushed onto navigation controller.

UINavigationBar class reference for pushViewController:animated: says:

Parameters
viewController
The view controller that is pushed onto the stack. This object cannot be an instance of tab bar controller and it must not already be on the navigation stack.

I suggest you present that tab bar controller modally instead of pushing it and you will solve both of these issues. To add a navigation bar with title, embed the view controller #6 in navigation controller, then in this tab bar controller that you will present.

So your storyboard would look something like this:

UITabBarController
+ (tab) UINavigationController
        + (push) UITableViewController
        + (push) UITableViewController
        + (modal) UITabBarController
                  + (tab) UINavigationController
                          + (push) UITableViewController (set title)