Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

navigationController title

I am working on an app with a navigation controller. I know how to set the title when the view loads initially. I push a new view controller and set it's title. Now the problem is when I press the back button, the title for the original view controller is not there anymore. I tried to do...

- (void)viewWillAppear:(BOOL)animated {
    self.navigationController.title = @"Some Title";
}

This did not set the title though. Does anyone know what I can do?

like image 963
Jared Grimes Avatar asked Oct 04 '11 06:10

Jared Grimes


People also ask

What is a UINavigationController?

A container view controller that defines a stack-based scheme for navigating hierarchical content.

What is Navigationitem?

The navigation item used to represent the view controller in a parent's navigation bar.

What is Interactivepopgesturerecognizer?

The gesture recognizer responsible for popping the top view controller off the navigation stack.


2 Answers

The UINavigationController gets the value for the title from the current UIViewController.

To set a the title for a view Controller, simply do the following:

- (void)viewDidLoad {

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

For each of your View Controllers, including the root one.

like image 142
Christopher A Avatar answered Oct 07 '22 20:10

Christopher A


Try changing the navigation item's title.

[self.navigationItem setTitle:@"Some Title"];
like image 35
FedeH Avatar answered Oct 07 '22 18:10

FedeH