How can I set the Title for a UINavigation Bar programmatically?
self.title = @"My View";
or
navigationBar.topItem.title = @"My View";
Depending on if you are using a UINavigationController
or not.
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!";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With