ios - 导航 Controller 中的 backBarButtonItem 未显示

标签 ios ios4

我从 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/

相关文章:

ios - 在没有确认对话框的情况下发起电话调用,如 1-2-Contact

iPhone:如何允许在自定义单元格的表格 View 中进行多项选择?

ios - 后台期间的 EAAccessory/EASession 拆卸

ios - 无法关闭应用中显示的推送通知

objective-c:在 UIImage 或 UIImageView 上画线

iphone - 如何以编程方式在 iPhone 上启动 Contacts.app

ios - Appium 测试 - "Sdk 9.3 was not in the list of simctl sdks"

ios - Firebase 数据比较 swift

ios - 如何不断获取 ARCamera 的旋转/欧拉角度值

ios - 如何更改导航栏后退按钮的字体?