如果您想更改 NavigationBar 标题,请尝试以下方法之一:
[self.navigationController.navigationItem setTitle:@"Title"];
[self.navigationItem setTitle:@"Title"];
[self setTitle:@"Title"];
如果您想更改按钮标题,请将其放在同一类中:
- (void)setLeftBarButtonTitle:(NSString *)title action:(SEL)selector
{
UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:title style:UIBarButtonItemStyleBordered target:self action:selector];
[self.navigationItem setLeftBarButtonItem:leftButton];
}
- (void)setRightBarButtonTitle:(NSString *)title action:(SEL)selector
{
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:title style:UIBarButtonItemStyleBordered target:self action:selector];
[self.navigationItem setRightBarButtonItem:rightButton];
}
设置按钮标题和操作的示例:
// Change button titles and actions any time
[self setLeftBarButtonTitle:@"Back" action:@selector(goBack)];
[self setRightBarButtonTitle:@"Something" action:@selector(doSomething:)];
// Change button titles with no actions
[self setLeftBarButtonTitle:@"Nothing" action:nil];
[self setRightBarButtonTitle:@"Nothing" action:nil];
// Remove buttons from navigation bar
[self.navigationItem setLeftBarButtonItem:nil];
[self.navigationItem setRightBarButtonItem:nil];