Want to change NavigationItem title

11,331

Solution 1

Navigation controller gets the title from the viewcontroller so this will do the job

- (void)viewDidLoad {

   [super viewDidLoad];
   self.title = @"Some Title";
}

Solution 2

This works for me:

self.navigationItem.title = @"YourTitle"; 

Hope it helps.

Solution 3

self.title = @"My Title"

This will change the navigation bars title as well as the title elements that refer to this view controller (eg. tab bar etc.)

self.navigationItem.title = @"My Title";

This will change only the title for the navigation bar for current view controller.

Share:
11,331
Eli Braginskiy
Author by

Eli Braginskiy

Updated on September 16, 2022

Comments

  • Eli Braginskiy
    Eli Braginskiy over 1 year

    I've embedded my first view into a NavigationController and then i set the segue as push. I want to change in each view the title of the Navigation bar to display something and update it through my code. i tried to call the navigation controller like this:

    self.navigationController.navigationBar.topItem.title = @"YourTitle";
    

    but this wont work, how can I do it?

  • Isaac Bosca
    Isaac Bosca over 5 years
    After you add a Navigation Item, you should use this sollution; instead, if you didn't add any navigation item, you can use simply: self.title. Thanks.