IPhone: setting the title bar navigation

Hey there. I'm still pretty new to iPhone development, and I am having problems with how to change the name of my navigation bar. For another question on this site, someone recommended using:

viewController.title = @"title text"; 

but this does not work for me ... Do I need to add a UINavigationController for this? Or maybe just exit my subclass of UIViewController? If this helps, I defined the navigation bar in IB, and I'm trying to set its title in my subclass of UIViewController. This is another one of those simple things that gives me a headache. Put self.title = @ "header text"; in viewDidLoad and initWithNibName didn't work either. Does anyone know what is going on and how is it going right?

Thank!

+79
objective-c iphone uinavigationitem uinavigationcontroller uinavigationbar
Feb 17 '10 at 12:54
source share
14 answers

The view controller must be a child of some UINavigationController for the .title property. If the UINavigationBar is just a view, you need to click the navigation element containing the title, or change the last navigation element:

 UINavigationItem* item = [[UINavigationItem alloc] initWithTitle:@"title text"]; ... [bar pushNavigationItem:item animated:YES]; [item release]; 

or

 bar.topItem.title = @"title text"; 
+146
Feb 17 '10 at 13:01
source share

if you do all this using the code in the viewDidLoad method of the viewDidLoad , you should only add self.title = @"title text";

something like that:

 - (void)viewDidLoad { [super viewDidLoad]; self.title = @"title"; } 

you can also try self.navigationItem.title = @"title";

also check if your navigationItem is not empty, and if you set a custom background to the navigation bar, check if a title is specified without it.

+117
Feb 17 '10 at 12:58
source share

There is one problem using self.title = @"title";

If you use the navigation bar with the tab bar, the above line also changes the label for the tab bar item. To avoid this, use the suggested @testing

 self.navigationItem.title = @"MyTitle"; 
+30
Mar 09 '11 at 23:20
source share

If you want to change the title of the navigator (and not the name of the button on the navigation bar!), This code will work.

 self.navigationController.topViewController.title = @"info"; 
+12
Aug 27 '13 at 13:02
source share

If you want to change the navBar header inside the tabBar controller, do the following:

 -(void)viewDidAppear:(BOOL)animated { self.navigationController.navigationBar.topItem.title = @"myTitle"; } 
+9
Apr 11 '13 at 9:36
source share

In my navigation based application, I do this:

 myViewController.navigationItem.title = @"MyTitle"; 
+5
Sep 22 '10 at 16:00
source share

By default, the navigation controller displays the title "topitem"

so you can use your viewdidload method of your application. I tested it and it works

 navController.navigationBar.topItem.title = @"Test"; 
+4
Mar 20 '11 at 22:22
source share

I had navigation controllers built into the TabbarController. It worked

 self.navigationItem.title=@"title"; 
+4
Mar 29 2018-12-12T00:
source share
 UINavigationItem* item = [[UINavigationItem alloc] initWithTitle:@"title text"]; ... [bar pushNavigationItem:item animated:YES]; [item release]; 

This code worked.

+2
05 Oct 2018-11-11T00:
source share

If you work with Storiesboards, you can click on the controller, switch to the properties tab and set the title text there.

+2
Feb 18 '13 at 11:01
source share

I think you need a dynamic header, so you do not set it to IB.

And I assume that your viewController is listed in the NIB?

Perhaps try setting it to a dummy value in IB and then debugging the methods to see which controller has the dummy value - provided that it appears as a header ...

+1
Feb 17 '10 at 12:59
source share

Inside TableViewController.m

self.navigationController.navigationBar.topItem.title = @ "Blah blah Some Amazing title";

+1
May 21 '14 at 5:21
source share

For all of your Swift crews, this worked great for me. This, in particular, is one of the shorter ways to customize the header:

 override public func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { if segue.identifier == "presentLineItem" { print("Setting Title") var vc = segue.destinationViewController as! LineItemsTableViewController vc.navigationItem.title = "Line Item" } } 
+1
Apr 08 '15 at 16:58
source share

What worked for me was self.titleLabel.text = @"New Title";

0
Dec 05 '17 at 2:48 on
source share



All Articles