0
votes

I a writing an app (iOS8) that ultimately needs to load a UITabBarController via a segue from a UITableView. For the most part this setup can be done via Storyboards and works as expected, however I would also like to add a UIButtonBarItem to the destination view which is where the problems start.

A setup that works (without a UITabBarController) can be configured as follows

  1. The button uses a "Show" segue to display the final view controller
  2. The second UIBarButtonItems are added by copying over the Navigation Item from the first view controller (How to add buttons to navigation controller visible after segueing?)

Working setup

If I run this in the Simulator, everything works as expected and I see both the back button and the desired "Add" UIBarButtonItem:

Working in Simulator

If I then embed the final view controller in a UITabBarController, the UIBarButtonItem I added disappears and so far any changes I have made to the storyboard setup (adding a UINavigationController in between the UITabBarContoller and the last view for example) or attempts to add the UIBarButtonItem programatically don't make a difference:

Not working setupNot working simulator

Is there anyway to get the final setup working with both a UITabBarController and UIBarButtonItems?

2
Try adding a navigation controller after the tab bar controller but before the destination view controller...Jacob
Unfortunately I tried that and it does not seem to make a difference (sorry forgot to mention that setup). I still see the same UINavigationBar without the add button.robowen5mac
Do you have a problem using the deprecated "Push" segues?Jacob
Same result as before.robowen5mac
I have the same setup in one of my apps and it works fine. Not sure why you are having issues, but I did add a few lines of code in my custom Tab Controller that may help you. I think the issue is that the nav bar from the original navigation controller is still being shown, so subclass UITabBarController and put this line in viewWillAppear [self.navigationController setNavigationBarHidden:YES];Jacob

2 Answers

0
votes

I have the same setup in one of my apps and it works fine. Not sure why you are having issues, but I did add a few lines of code in my custom Tab Controller that may help you. I think the issue is that the nav bar from the original navigation controller is still being shown, so subclass UITabBarController and put these lines in viewWillAppear:

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationItem setHidesBackButton:YES];
    [self.navigationController setNavigationBarHidden:YES];
    self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}

In my app, the views before the tab bar controller were login/register views, so there was no reason to navigate back to them after entering the tab controller "stack," but I'm sure it won't be difficult to add a back button that accomplishes this. I believe you only need the [self.navigationController setNavigationBarHidden:YES]; line, which only hides the nav bar instead of hiding the back button or disallowing the pop gesture.

0
votes

I know this is late but I just want to add swift 3 code. The reason being that the NavigationBarA of the tabBarController is hiding your NavigationBarB that sits in between your tabBarController and the final ViewController. So you just have to set to hide the NavigationBarA

in viewWillAppear of your final ViewController you can add the following (without a need to subclass tabBarController)

self.tabBarController?.navigationController?.setNavigationBarHidden(true, animated: false)