I have a navigationController-based app. I want to change the title of the back button for the root view controller. I have tried the following code in the rootViewController's viewDidLoad method, but no success:
self.navigationItem.backBarButtonItem.title = @"Back";
Any ideas?
In case you want to initialize UIBarButtonItem programmatically in Swift 4+ should be done as following: editButton = UIBarButtonItem(title: "Edit", style: . plain, target: self, action: #selector(editAct)).
Select the UIBarButtonItem in Interface Builder , open the inspector (Command + Shift + I) , and select "Custom" under the dropdown next to Identifier .
I've had success by creating my own UIBarButtonItem instead of setting the title of the existing one:
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil]; self.navigationItem.backBarButtonItem = backButton; [backButton release];
The title of the back button is either:
If you are setting the back button for the current view controller's navigation item you are not setting the button that get's displayed in the current view. You are in fact setting the back button that will be used if you push another view controller from it.
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