我从 NavigationViewController 模板开始我的 xcode 项目。现在,当我推送一个 View 时,该 View 默认带有一个编辑按钮,没有后退栏按钮。我已经注释掉了 editButton 代码和相应的 setEditing 委托(delegate)方法。但我无法让后退按钮显示出来。我做错了什么?
推送新 View :
PlaylistViewController *playlistViewController = [[PlaylistViewController alloc] init];
playlistViewController.managedObjectContext = self.managedObjectContext;
[self.navigationController pushViewController:playlistViewController animated:YES];
[playlistViewController release];
在我的 PlaylistViewController 中:
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"";
// self.navigationItem.leftBarButtonItem = self.editButtonItem;
// doesn't matter if this is here or not
self.navigationItem.hidesBackButton = false;
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject)];
self.navigationItem.rightBarButtonItem = addButton;
[addButton release];
}
最佳答案
当您告诉 UINavigationController 到 pushViewController 时,它会自动将 navigationItem.leftBarButtonItem 设置为一个按钮,其标题为前一个 UIViewController 的标题。
如果没有设置标题,默认文本为“返回”。
如果标题设置为“”,则根本不会显示任何按钮。
self.title = @"";
尝试更改此文本,您的后退按钮应与此处设置的文本匹配。
或者您可以从新的 UIViewController 中手动覆盖 leftBarButtonItem 的文本。
关于ios - 导航 Controller 中的 backBarButtonItem 未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6769781/