royco
royco

Reputation: 5529

How to embed UITabBarController inside UINavigationController?

I want to embed a UITabBarController inside a UINavigationController. I found a similar question here on StackOverflow, but my attempted implementation does not let me add a UIBarButtonItem to navigationItem.rightBarButtonItems.

Below is a screenshot of my implementation. "Button 1" and "Button 2" are not displayed in the running app. Any ideas what I'm doing wrong?

UITabBarController inside UINavigationController screenshot

Upvotes: 2

Views: 1417

Answers (1)

arturdev
arturdev

Reputation: 11039

I think your "Button 1" and "Button 2" are not visible because there are overlapped by the navigation bar of the root navigation controller.
So you can do the following:
Step 1. Create a UITabBarController subclass and assign it in IB to your tab bar controller.
Step 2. In -viewWillAppear: method just hide navigation bar of root navigation controller

- (void)viewWillAppear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:YES animated:animated];
}

Step 3: Bring back navigation bar when you go back to root view

- (void)viewWillDisappear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}    

Upvotes: 3

Related Questions