By default the back button uses as a text on it a title of a viewcontroller. Can I change text on the back button without changing a title of a view controller? I need this
In Swift5, the backBarButtom cannot be edited. Hence, we need to hide the backBarButtom first, then use a customised leftbarButtom to replace backBarButtom. Here is the detailed solution: https://stackoverflow.com/a/63868300/13939003
Thanks Marco... that helped me...
Here is what i did.
If you are using a tableView to navigate to different views... put the code:
self.navigationItem.backBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil] autorelease];
In your didSelectRowAtIndexPath
method... of the first Controller... Controller A.
When you navigate to Controller B the button will have the title "Back".
This worked for me:
self.navigationController.navigationBar.topItem.title = "Back"
You can do it in the storyboard. Find the view controller you want to go back to (the one with the long title), select it's Navigation Item, and open the Attributes Inspector (Alt+Cmd+4), insert the custom Back Button title.
I finally knew why these answers did not work for me at first. I set the title in storyboard. When i set the title on code. it works!
self.navigationItem.title = @"Main Menu";
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@" " style:UIBarButtonItemStyleBordered target:nil action:nil];
[[self navigationItem] setBackBarButtonItem:backButton];
My solution was to set title when the view controller is pushed to navigation stack and reset it by use of delegate method before pushed vc closes:
So I put the title change in calling view controller when I push the other view controller like:
self.pushedVC = [self.storyboard instantiateViewControllerWithIdentifier:@"pushedVCIdentifier"];
self.pushedVC.delegate = self;
[self.navigationController pushViewController:self.pushedVC animated:YES];
self.title = @"Back";
and in delegate callback function (which I invoke in viewWillDissapear):
-(void)pushedVCWillClose:(PushedVC *)sender
{
self.title = @"Previous Title";
}