How to change the title of the UINavigationBar bac

2020-08-17 06:56发布

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"?

2条回答
Fickle 薄情
2楼-- · 2020-08-17 07:08

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;
查看更多
趁早两清
3楼-- · 2020-08-17 07:27

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"];
}
查看更多
登录 后发表回答