如何更改 uinavigationbar 后退按钮文本
我目前正在尝试更改加载表格单元格触摸的子视图的后退按钮文本。然而,即使我尝试实现它的方式,它仍然在后退按钮中显示父母的标题。
我正在尝试将新值加载到 viewdidload 方法内的后退按钮中,
UIBarButtonItem *myBarButtonItem = [[UIBarButtonItem alloc] init];
myBarButtonItem.title = @"Back";
self.navigationItem.backBarButtonItem = myBarButtonItem;
[myBarButtonItem release];
但它不起作用。
I am currently trying to change the back button text of a subview that is loaded of a tablecell touch. However even with the way I am trying to implement it it still shows the parents title in the back button.
I am trying to load a new value into the back button inside viewdidload method like so
UIBarButtonItem *myBarButtonItem = [[UIBarButtonItem alloc] init];
myBarButtonItem.title = @"Back";
self.navigationItem.backBarButtonItem = myBarButtonItem;
[myBarButtonItem release];
however its not working.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
您需要从以前的视图更改
self.navigationItem.backBarButtonItem
,而不是当前视图(我知道,这似乎有点不合逻辑)。例如,在表视图中,您可以执行以下操作:You need to change
self.navigationItem.backBarButtonItem
from previous view, not current view (I know, it seems to be a little bit illogical). For example, in your table view you can do the following:在您阅读并重新阅读并尝试每个设置之前,文档并不那么清晰。
要更改默认后退按钮的标题,请在
viewDidLoad()
中添加此行。如果您希望按钮不可见,请将值设置为
@""
空字符串。This is where the documentation is not so clear until you have read and re-read and play around with each settings.
To change the title of the default back button add this line in
viewDidLoad()
If you want the button to be invisible - then set the value to
@""
empty string.好吧,弄清楚了,我在父视图 tableView:didSelectRowAtIndexPath: 方法中发布了这段代码。这就是我的表格的外观,用户可以选择多个表格单元格。希望这有帮助。
Okay figured it out, I posted this code in the parent views tableView:didSelectRowAtIndexPath: method. this is how my one looks with multiple tablecells the user can select. Hope this helps.
使用 Xcode 5 更改后退按钮名称的最佳方法是编辑后退按钮将返回到的视图控制器上导航项的 IB 中的后退按钮字段。例如,如果您有一个转到详细信息屏幕的列表 TableViewController,请更改列表 TableViewController 的导航项(在 IB 中)上的后退按钮,以更改详细信息屏幕显示的后退按钮名称。
The best way with Xcode 5 to change the back button name is to edit the Back Button field in IB of the Navigation Item on the View Controller to which the back button will return. For example, if you have a list TableViewController that goes to a detail screen, change the Back Button on the list TableViewController's Navigation item (in IB) to change the back button name that the detail screen displays.
它不会按照你想要的方式工作。导航按钮将始终具有上一个视图的标题。但你可以做什么 - 在推送新视图之前更改第一个视图的标题。这是我能找到解决同样问题的唯一方法。
It's not gonna work the way you're trying to do. Navigation button will always have title of previous view. What you can do though - change title of first view before pushing the new one. This is the only was I could find to solve same problem.
到目前为止,您的代码看起来不错。
这段代码是在
语句之前执行(错误)还是在语句之后执行(好)?
Your code looks fine so far.
Is this code executed before the
statement (wrong) or after it (good)?
viewDidLoad之后
self.navigationController!.navigationBar.backItem?.title = "返回"
After viewDidLoad
self.navigationController!.navigationBar.backItem?.title = "Back"
我的建议是向家长页面标题栏添加一个单独的标签。
对我来说效果很好。
My suggestion was to add a separate Label to parents Page title Bar.
Worked fine for me.
这篇文章应该可以满足您的需求。
来自作者:
This article should do what you want.
From the author:
一个好方法是在调用子视图控制器之前在父视图控制器中设置后退按钮的标题,如下所示:
此标题将放置在子视图上的后退按钮中。这里重要的一点是该标题在子视图中用作父视图的后退按钮。
A good way to do this is to set the title of the back button in the parent view controller before calling the child like this:
This title will be placed in the back button on the child view. The important point to get here is this title is used in the child view as the back button to the parent view.