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"?
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.
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.
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;
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"];
}
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