UITabBarController does not display the name of other tabs

I am trying to make a UITabBarController programmatically. This seems to work, I have 2 tabs, the problem is that it does not display the second name of the tab in the RootViewController when it loads for the first time. Why?

This is when the RootViewController loads:

enter image description here

When I click on the second tab where there is no name, the title appears:

enter image description here

When I return, the title of the second tab still exists:

enter image description here

My question is why it does not appear when RootViewController boots.

my appDelegate method in didFinishLaunchingWithOptions file:

tabBarController = [[UITabBarController alloc] init];

MenuViewController *firstTab = [[MenuViewController alloc] initWithNibName:@"MenuViewController" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:firstTab];


FixtureViewController *secondTab = [[FixtureViewController alloc] initWithNibName:@"FixtureViewController" bundle:nil];
UINavigationController *navController2 = [[UINavigationController alloc] initWithRootViewController:secondTab];


self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = @[navController, navController2];

[self.window setRootViewController:tabBarController];
+3
source share
3 answers

Add a title to the view controller:

firstTab.title = @"Title to display 1";
secondTab.title = @"Title to display 2";
0
source

TabBar initialize, ViewDidLoad, viewDidAppear..

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.tabBarItem.title = @"Tabbar Title";
    }
    return self;
}
0

Instead of assigning the title property to the RootViewController, you should override the tabBarItem property on the first / second viewController. You can lazily load it ...

If you set the title property in the override of viewDidLoad (), it will not be applied until the view controller is actually loaded and viewDidLoad () is actually called. You can check it yourself by setting a breakpoint wherever you set your title / tabBarItem.

0
source

All Articles