如何更改“返回"的标题?导航栏上的按钮 [英] How do I change the title of the "back" button on a Navigation Bar

查看:28
本文介绍了如何更改“返回"的标题?导航栏上的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前左栏按钮默认值是加载当前视图的标题,即按下按钮(后退按钮)时显示的视图.

Currently the left bar button default value is the title of the view that loaded the current one, in other words the view to be shown when the button is pressed (back button).

我想将按钮上显示的文本更改为其他内容.

I want to change the text shown on the button to something else.

我尝试将以下代码行放入视图控制器的 viewDidLoad 方法中,但似乎不起作用.

I tried putting the following line of code in the view controller's viewDidLoad method but it doesn't seem to work.

self.navigationItem.leftBarButtonItem.title = @"Log Out";

我该怎么办?

谢谢.

推荐答案

这应该放在调用名为NewTitle"的 ViewController 的方法中.就在 push 或 popViewController 语句之前.

This should be placed in the method that calls the ViewController titled "NewTitle". Right before the push or popViewController statement.

UIBarButtonItem *newBackButton = 
        [[UIBarButtonItem alloc] initWithTitle:@"NewTitle" 
                                         style:UIBarButtonItemStyleBordered 
                                        target:nil 
                                        action:nil];
[[self navigationItem] setBackBarButtonItem:newBackButton];
[newBackButton release];

这篇关于如何更改“返回"的标题?导航栏上的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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