Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the title of the UINavigationBar back button to "Back"

When I push a view onto the navigation controller the back button's title get's set to the title of the previous view. How can I get the back button to just say "Back"?

like image 822
Christian Gossain Avatar asked Nov 08 '11 06:11

Christian Gossain


People also ask

How do I hide the back button?

Way 1: Touch “Settings” -> “Display” -> “Navigation bar” -> “Buttons” -> “Button layout”. Choose the pattern in “Hide navigation bar” -> When the app opens, the navigation bar will be automatically hidden and you can swipe up from the bottom corner of the screen to show it.

What is navigation Controller in IOS?

The navigation controller manages the navigation bar at the top of the interface and an optional toolbar at the bottom of the interface. The navigation bar is always present and is managed by the navigation controller itself, which updates the navigation bar using the content provided by its child view controllers.


2 Answers

Write this code in your viewwillappear:

UIBarButtonItem *_backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleDone target:nil action:nil];
self.navigationItem.backBarButtonItem = _backButton;
[_backButton release];
_backButton = nil;
like image 125
Baby Groot Avatar answered Nov 16 '22 00:11

Baby Groot


In the previous view controller, have it set its title in viewWillAppear, and then in the code that pushes the new view controller, have it change its title to 'Back.'

Example:

-(void)showNextScreen{
     [self setTitle:@"Back"]; 
     [self.navigationController pushViewController:asdf animated:YES];
}
-(void)viewWillAppear{
     [super viewWillAppear];
     [self setTitle:@"My Actual Title"];
}
like image 39
Tim Avatar answered Nov 16 '22 00:11

Tim