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

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

问题描述

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

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

在我的一个视图控制器上,我有一个添加按钮,其中代码以编程方式生成一个新的 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];
}

这是有效的,当我点击添加按钮时,它会深入查看新视图。在 myDdViewController.m viewDidLoad 方法内,我有:

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];

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

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?

谢谢

推荐答案

这只会起作用在viewController之后的每个子节点上有 self.navigationItem.backBarButtonItem

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

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

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