Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UINavigationController how to set title

I have a Controller/View for a generic list of items, that can be extended for displaying a custom list.. Listing and navigation works fine.. but I can't change the title of UINavigationController. In the generic Controller:

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.view addSubview: navigationController.view];
}
- (void)setNavigationTitle: (NSString *)title
{
    NSLog(@"set title: %@", title); // this works
    self.navigationController.title = title; // Nothing works here
}

Then, the extended class does..

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setNavigationTitle: @"Custom list"];
}

The navigationBar still have "Item" as title :(

like image 759
grilix Avatar asked Sep 09 '25 15:09

grilix


1 Answers

In your UIViewController there is a title property and it is that property that will be displayed by the NavigationController. So when pushing a new UIViewController onto the navigation stack set the title of that UIViewController to whatever is appropriate.

In your case it looks like it would be:

[self setTitle:@"WhateverTitle"];
like image 75
willcodejavaforfood Avatar answered Sep 13 '25 00:09

willcodejavaforfood