I allocated a UITabBarItem with a title (initWithTitle) and connected it to a UINavigationController.
I found out that if the navigation controller's root view controller has its own title, then that title permanently replaces the title specified on the tab bar item. For example, if the tab bar items' title is set to ONE and the navigation controller's root view controller's title is set to TWO, the tab bar item always shows TWO, not ONE. The only way to have the tab bar item show ONE is to omit the navigation controller's root title altogether.
The thing is, I want to have different titles for each, because the tab bar item doesn't always lead to the navigation controller's root view controller - it shows the last view controller that was pushed onto the navigation controller, which means that the root's title on the tab bar may be inappropriate. On the other hand, I can't just throw away the title in the navigation controller, because it is used on the navigation bar. Sort of Catch 22.
Is there a way around this?
I often use a navigationBar with a tabBar and almost never have the same title. The code I've used (in init
) reads:
// SET TAB BAR NAME AND IMAGE
[[self tabBarItem] setTitle:@"Short Title"];
[[self tabBarItem] setImage:[UIImage imageNamed:@"MyImage.png"]];
// SET NAVIGATION
[[self navigationItem] setTitle:@"Much Longer Title"];
I've never encountered a problem with this.
Well, here's what I found out.
It seems that if you do:
MainNavController *main = [[MainNavController alloc] init];
UITabBarItem *tabBarItem = [[UITabBarItem alloc] initWithTitle:@"ONE" image:[UIImage imageNamed:@"one.png"] tag:1];
main.tabBarItem = tabBarItem;
[tabBarItem release];
and then, in the root view controller pushed to main, you do:
self.title = @"TWO";
then what happens is what I described above.
But I can fix it if I add the following line in the root view controller of main:
self.navigationController.tabBarItem.title = @"ONE";
It seems to be sort of a "timing" issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With