iPhone: Setting Navigation Bar Title
The view controller must be a child of some UINavigationController for the .title
property to take effect. If the UINavigationBar is simply a view, you need to push a navigation item containing the title, or modify the last navigation item:
UINavigationItem* item = [[UINavigationItem alloc] initWithTitle:@"title text"];
...
[bar pushNavigationItem:item animated:YES];
[item release];
or
bar.topItem.title = @"title text";
if you are doing it all by code in the viewDidLoad
method of the UIViewController
you should only add self.title = @"title text";
something like this:
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"title";
}
you could also try self.navigationItem.title = @"title";
also check if your navigationItem is not null and if you have set a custom background to the navigationbar check if the title is set without it.
There's one issue with using self.title = @"title";
If you're using Navigation Bar along with Tab bar, the above line also changes the label for the Tab Bar Item. To avoid this, use what @testing suggested
self.navigationItem.title = @"MyTitle";
If you want to change navbar title (not navbar back button title!) this code will be work.
self.navigationController.topViewController.title = @"info";
If you want to change the title of a navBar inside a tabBar controller, do this:
-(void)viewDidAppear:(BOOL)animated {
self.navigationController.navigationBar.topItem.title = @"myTitle";
}