views:

1007

answers:

2

I have a UINavigationController and UITabBarController visible at the same time. Both the tab bar buttons and the navigation bar take their text from the title of the currently active view.

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"View Title";

However I want the different. In fact I'd like the navigation controller title to remain the same whichever view is being displayed.

Any ideas?

Many thanks.

A: 

You'll have to manually assign the title name, as you are doing above, in your other view controllers.

If your view hierarchy is more than two levels deep, be wary as the back button will look a little strange to the user (unless you override it). In fact, if every view has the same title, that may look strange to the user, period...

Shaggy Frog
Shaggy, thanks for the comment. For each UIViewController:viewDidLoad I'm calling: self.title = myObject.name; self.tabBarItem.title = @"<tab name>";However, while this names the tabBarItems correctly, but the NavigationController title is blank. Very strange. My need is for the the tabs are different views on the same object.
Zen-C
From the docs at http://developer.apple.com/IPhone/library/documentation/UIKit/Reference/UINavigationController_Class/Reference/Reference.html: "If you want to display a different title than the one associated with the view controller, set the title property of the view controller’s navigation item instead."
Shaggy Frog
Thanks for the tip. I've tried it (... self.title = @"Core Data"; self.navigationItem.title = dataObject.name; ...) in the viewDidLoad however that doesn't seem to work either. Neither does setting the NavigationItem's titleView.
Zen-C
Is self.navigationItem nil?
Shaggy Frog
As soon as I execute self.navigationItem.title=dataObject.name it's created.
Zen-C
That's impossible. If it's nil, I suspect your view controller was not pushed onto the UINavigationController's stack properly.
Shaggy Frog
A: 
   -(void)viewDidLoad{
 [self setTitle:@"Custom Title goes here"];
}

This worked for me.

Marius Ciocanel