navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? [英] navigationItem.backBarButtonItem not working? Why is the previous menu still showing as the button?

查看:11
本文介绍了navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在下钻导航控制器中自定义我的后退按钮.

Trying to customize my back button in a drilldown navigation controller.

在我的一个视图控制器上,我有一个 Add 按钮,代码以编程方式生成一个新的 UIViewController:

On my one view controller I have an Add button where the code programatically generates a new UIViewController:

- (void)add:(id)sender 
{
    MyAddViewController *addController = [[MyAddViewController alloc] initWithNibName:@"MyAddViewController" bundle:nil];

    [self.navigationController pushViewController:addController animated:YES];

    [addController release];
}

这有效,当我单击添加按钮时,它会向下钻取到新视图.在 MyAddViewController.mviewDidLoad 方法中,我有:

This works and when I click the add button it drills down into the new view. Inside the viewDidLoad method of MyAddViewController.m I have:

self.navigationItem.backBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil] autorelease];

但这不起作用.导航控制器中的后退按钮仍然是堆栈上前一个视图控制器的 title.这条线似乎什么也没做.我错过了什么吗?

But this isn't working. The back button in the navigation controller remains the title of the previous view's controller on the stack. It seems that line does nothing. Did I miss something?

谢谢

推荐答案

这仅适用于具有 self.navigationItem.backBarButtonItem 的 viewController 之后的每个子节点.

This will only work on each child after the viewController that has self.navigationItem.backBarButtonItem.

这篇关于navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆