Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't set UINavigationController title

So here's how I set up things in my app. I have a UINavigationController which has a UITabBarController as the rootViewController. The rootViewController has 3 tabs in it. I have tried many different ways to set the title, ranging from:

self.title = @"title";

self.navigationController.title = @"title";

self.navigationItem.title = @"title";

and none of it works

Why is this?

UPDATE:

for some weird reason self.parentViewController.title = @"Map"; actually worked....

like image 434
adit Avatar asked Jun 06 '26 22:06

adit


1 Answers

I am guessing you want is to set the text that appears in the center of the navigation bar. If so, navigationItem is definitely not what you want. That's for setting buttons in the navigation bar.

The less obvious part of setting the title is that the text that will appear in the navigation bar is the title of the ViewController that is on top. In other words, the last ViewController that was pushed. So what you want to do is to set your self.title in your ViewContoller. You can do it ViewContoller's init or viewDidLoad.

like image 86
rjgonzo Avatar answered Jun 10 '26 15:06

rjgonzo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!