Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the UINavigationController back button name?

I have a UIViewController and I'm navigating from my first view controller to second view controller and I want to change the name of the button shown on the navigationcontroller for going back ....

SecondViewController *secondController = [[SecondViewController alloc]                                               initWithNibName:nil                                               bundle:NULL];  [self.navigationController pushViewController:secondController  animated:YES]; 

now in the second viewcontroller I want change the name of the button in the navigationController.

like image 302
Bulla Avatar asked Mar 26 '12 11:03

Bulla


People also ask

How do I add a back button to my storyboard?

Storyboard. You can also set this in the Storyboard. Select UINavigationBar and select the Attributes Inspector tab. Then you can change those two images under Back and Back Mask attributes.


1 Answers

If you wish to do this programmatically, it can be done like this:

Objective-C

UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@"Custom"                                                              style:UIBarButtonItemStyleBordered                                                             target:nil                                                             action:nil];  [self.navigationItem setBackBarButtonItem:backItem]; 

Swift

let backItem = UIBarButtonItem(title: "Custom", style: .Bordered, target: nil, action: nil) navigationItem.backBarButtonItem = backItem 

However, if you prefer using Interface Builder, just select the UINavigationItem that you wish to set the back button for, and navigate to the attributes inspector to change the back button's title.

enter image description here

NOTE: It is important to remember that you must configure this on the view controller that you would be returning to upon tapping the back button, not the currently visible view controller.

like image 160
Mick MacCallum Avatar answered Nov 16 '22 00:11

Mick MacCallum