Storyboard navigation controller and tab bar controller
Solution 1
For changing the UINavigationBar
title (with no need to create 2 other UINavigationController
) you can just use
[self.parentViewController.navigationItem setTitle:@"Title"];
and for adding the right button use
self.parentViewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(myRightButton)];
on viewDidLoad
method for each UIViewController
referenced from your UITabBarController
.
If you want to work with "navigation structures" inside your UIViewController
from TabItems
so you could edit your BUFViewController.m to that:
#import "BUFViewController.h"
@interface BUFViewController ()
@end
@implementation BUFViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self.parentViewController.navigationController setNavigationBarHidden:YES];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(done)];
}
-(void)done{
[self.parentViewController.navigationController popToRootViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
You have to think as your UITabBarController
is inside your parent NavigationController
, so you want to hide the parent UINavigationBar
and show yours.
After that, you'll be able to back to your table using popToRootViewControllerAnimated
: on the parent's UINavigationController
.
Hope that helps :)
Solution 2
Just in case anyone was looking for a swift approach:
tabBarController?.title = "Your Title"
tabBarController?.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Right Button Title", style: UIBarButtonItemStyle.Plain, target: self, action: "rightButtonFunction")
The code is best placed in viewDidAppear
or viewWillAppear
so the title and button change as the different tabs are pressed.
You also wouldn't need the extra navigation controllers with this approach.
Solution 3
I looked at your test app, and I do see the title, very faintly, under the navigation bar. You can see both navigation bars if you select the tab bar controller, and uncheck the "Under Top Bars" box. However, this gives you a weird shadow on the navigation bar. I don't know if there's an easy way to fix this, but I don't think this UI with two navigation bars looks good any way. You might want to eliminate the initial navigation controller, and use a modal segue to present the tab bar controller instead. You could add a bar button item to the navigation controllers you still would have to do the dismissal of the modal view controller.
Related videos on Youtube
Matthijn
Updated on February 24, 2020Comments
-
Matthijn about 4 years
I am trying to get the following setup in Storyboard.
Where I have a table view in the beginning, and when I tap a cell it needs to transition to the tab bar controller, which works. But now I want a title and an extra navigation bar button in the the 2 most right controllers.
But I can't seem to drag a button to there or when setting the title, nothing shows up. How can I achieve this setup in storyboard?
Updated question, based on answer below.
When I have this new setup (thus with an extra navigation controller in between) I can set the title in the storyboard, but when running the app, the added title is not shown.
I have uploaded a Xcode project with exactly that setup. Perhaps it can come in handy.
-
Nischal Hada over 8 yearsIs your problem solved i gt the similar issue
-
-
Matthijn about 10 yearsYes, I have tried that (I have updated my question) since that was my initial idea. Then I can place a title in the storyboard builder, but it does not show up when I am running the app.
-
Kamaros about 10 yearsHave you tried explicitly setting the top bar in the attributes inspector view of your storyboard instead of using "Inferred"?
-
Matthijn about 10 yearsIf by explicitly setting you mean using this input field, then yes. As you can see I can also drag a bar button out in the bar. But when running that app, nothing is shown for that view only the empty navigation bar.
-
Matthijn about 10 yearsThanks for your reply. I have tried your idea, and it works, but it also kills the "back button" which normally would appear. (Since that is added to the overlaying navigation bar). Don't know if having 2 navigation bar's is the way to go here. But with one (my first screenshot) I can't seem to add titles or buttons.
-
Matthijn about 10 yearsI see your edit and could add the back button in code indeed, and it works. But is there not something I am missing here? That this could be done in a more elegant way.
-
ColdLogic about 10 yearsYou can change the title of the tabBarController to update the title while maintaining the navigation back button.
[[self tabBarController] setTitle:@"First View Controller"];
. Dirty, but it works. -
ErickBergmann about 10 yearsI've made an edit, that should work pretty for you :)
-
David M about 9 yearsIn case this helps anyone else, here is a similar approach in Swift: self.navigationItem.setRightBarButtonItem(UIBarButtonItem(barButtonSystemItem: .Search, target: self, action: "barButtonItemClicked:"), animated: true)