How to change the title of the UINavigationBar back button to “Back”

僤鯓⒐⒋嵵緔 提交于 2019-12-10 02:08:08

问题


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


回答1:


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;



回答2:


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


来源:https://stackoverflow.com/questions/8046622/how-to-change-the-title-of-the-uinavigationbar-back-button-to-back

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!