如何将UINavigationBar后退按钮的标题更改为“返回”

时间:2011-11-08 06:12:38

标签: objective-c uinavigationcontroller uinavigationbar

当我将视图推到导航控制器上时,后退按钮的标题被​​设置为上一个视图的标题。如何让后退按钮只是说“后退”?

2 个答案:

答案 0 :(得分:30)

将此代码写入viewwillappear

UIBarButtonItem *_backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleDone target:nil action:nil];
self.navigationItem.backBarButtonItem = _backButton;
[_backButton release];
_backButton = nil;

答案 1 :(得分:3)

在上一个视图控制器中,让它在viewWillAppear中设置其标题,然后在推动新视图控制器的代码中,将其标题更改为“返回”。

示例:

-(void)showNextScreen{
     [self setTitle:@"Back"]; 
     [self.navigationController pushViewController:asdf animated:YES];
}
-(void)viewWillAppear{
     [super viewWillAppear];
     [self setTitle:@"My Actual Title"];
}