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

时间:2021-08-18 20:29:35

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 个解决方案

#1


30  

Write this code in your viewwillappear:

在viewwillappear中写下此代码:

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

#2


3  

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.'

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

Example:

例:

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

#1


30  

Write this code in your viewwillappear:

在viewwillappear中写下此代码:

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

#2


3  

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.'

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

Example:

例:

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