0
votes

(Question in iOS7) I know it is not good to put TabBarController in a NavigationController. But, is there any solution if it's really needed? The stroyboard is like "This".

Here's the problem:

  1. In 'ItemTVC', the backBarItem will not pop to its parent 'SampleTVC', but to root 'ProjTVC', why?

  2. In 'SampleTVC', if called:
    [self.navigationController setNavigationBarHidden:NO]
    And
    [self.navigationController.navigationController setNavigationBarHidden:YES]
    to hide the root navigation bar and show the nearest ancestor navigation bar, how to set nearest ancestor navigation bar's leftBarButtonItem to backBarButtonItem of the root's navigationItem?

  3. If both navigation bar are not hidden, the root navigation bar will dominate (be shown on top of nearest ancestor navigation bar. But, how to add a rightBarButtonItem to the root navigation bar? I tried:
    UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)] and self.navigationItem setRightBarButtonItem:addButton, but no button is shown.

  4. Setting self.navigationController.backBarButtionItem never has any effect to its subsequent navigated views. It is always nil.

It seems to me that self.navigationItem get completed messed up when TabBarController and NavigationController are mixed in this configuration.

(An ugly solution I'm using is: hide the root navigation bar first, then assign a UIBarButtonItem to nearest ancestor navigation bar's leftBarButtonItem, then call [self.navigationController.navigationController popViewControllerAnimated:YES],
but this button will be a different style as a 'backBarButtionItem' should be. How to get a copy of the currently displayed backBarButtionItem in a different navigation bar's item?)

2

2 Answers

0
votes

Thank you for your tips. I've removed the navigation controller. Now it can segue properly. (Question 1 is solved).

Regarding to missing RightBarButton, I actually solved by adding self.navigationItem.rightBarButtonItem = addButton; to the customized tabBarController's viewDidLoad first, then in tabBarController's sub-controllers, add

if (self.tabBarController) {     
self.tabBarController.navigationItem.rightBarButtonItem = addButton;}
else{self.navigationItem.rightBarButtonItem = addButton;
}

This is really tricky to find that self.navigationItem is actually hidden when it's inside a tab controller. The real shown navigationBar is actually from self.tabBarController.navigationItem

0
votes

You really shouldn't be doing any of this, both from an architecture standpoint and a UX standpoint. But... You don't need the second set of navigation controllers. They should use the push and pop of the root navigation controller just fine. Tab controllers in Nav controllers is bad. But Nav controllers inside tab controllers inside nav controllers is worse.

Edit:

If you want to fix the navigation items, you need to set them on the Tab Controller. It is the "current" view controller on the navigation controller and so it's navigation items will be what are shown on the navigation bar.