Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set the Title for a UINavigation Bar programmatically?

Tags:

iphone

How can I set the Title for a UINavigation Bar programmatically?

like image 773
jp chance Avatar asked Oct 30 '09 02:10

jp chance


2 Answers

self.title = @"My View";

or

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

Depending on if you are using a UINavigationController or not.

like image 187
marcc Avatar answered Oct 13 '22 02:10

marcc


The title that is shown in UINavigationBar comes from the currently active UIViewController.

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

In our app 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!";
}
like image 22
richleland Avatar answered Oct 13 '22 03:10

richleland