In my iPhone application, I have a tab bar. This tab bar holds a UINavigationController. I have:
- In Interface Builder set the tab item title to 'Create New'
- In the UINavigation controller I have
self.tabBarItem.title = 'Create New';
andself.title = 'Create New';
- In the UIViewController pushed onto the controller: self.tabBarItem.title = 'Create New'; but
self.title = 'Blah';
.
But, always, the self.title of the first view controller pushed onto the navigation controller is shown (Blah). How would you set the title of the tab bar item? Thanks, Isaac Waller
I just solved the same issue. I was using
self.tabBarItem.item
for the 1st tab of mytabBarController
, which is the first and only one that loads itsnavigationController
. So for the first tab in a tab bar you have to set the title differently. I'll try to illustrate:tab bar with 3 tabs (a
UINavigationController
provides content each tab)self.tabBarItem.item
to '1st')self.title
to 'tab1 View'self.tabBarItem.item
to '2nd')self.title
to 'tab View'self.tabBarItem.item
to '3rd')self.title
to 'tab3 View'When the tab bar loads all of its
viewControllers
for each of the 3 tabs, the tab buttons in the tab bar have these labels:This is because the 2nd and 3rd nav controllers aren't loaded until the user selects those tabs. The 1st tab is loaded when the
UITabBarController
is loaded and due to the order of events it replaces thetabBarItem.title
with the navController's rootViewController'sself.title
.Solution
To fix this, you simply use
self.navigationItem.title
instead ofself.title
. You ONLY have to do this for the 1st tab's navController's rootViewController.I hope that makes sense. You did solve your own problem, but I wanted you and anyone else to know WHY it works like this.
I found if I used
self.navigationItem.title = 'Blah';
instead ofself.title
, it would work.