How can I programmatically customize the title for the UINavigation panel?

How can I customize the title for the UINavigation panel?

+6
iphone
source share
4 answers
self.title = @"My View"; 

or

 navigationBar.topItem.title = @"My View"; 

Depending on whether you use a UINavigationController or not.

+16
source share

The header displayed in the UINavigationBar comes from the currently active UIViewController.

For example, let's say we need a UINavigationController with a root view controller, MyCustomViewController.

In our application delegate:

 - (void)applicationDidFinishLaunching:(UIApplication *)application { UIViewController *myCustomViewController = [[MyCustomViewController alloc] init]; navController = [[UINavigationController alloc] initWithRootViewController:myCustomViewController]; [window addSubview:navController.view]; [window makeKeyAndVisible]; } 

In MyCustomViewController.m:

 - (void)viewDidLoad { self.title = @"Hello World!"; } 
+3
source share

in your controller implementation file:

 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if(self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { self.title = @"My Title"; } return self; } 

this should work.

0
source share

I was able to successfully set the header on the pushcontroller. Rather, before the push. Here is my code for this.

  _chatTableViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"ChatTableViewController"]; _chatTableViewController.title = @"Live Chat"; [[self navigationController]pushViewController:_chatTableViewController animated:YES]; 
0
source share

All Articles