Storyboard UINavigation 控制器后退按钮文本 [英] Storyboard UINavigation Controller Back Button Text

查看:17
本文介绍了Storyboard UINavigation 控制器后退按钮文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 XCode 4.5.1 创建一个带有导航控制器的故事板应用程序时,我很难为任何被推送的视图控制器设置 BACK 按钮.我正在使用 segue,并且视图控制器按预期显示.但是我想动态更改导航栏和后退按钮的名称并将其放在我的 ViewWillAppear 中:

In XCode 4.5.1 creating a storyboard app with a Navigation controller, I am having a hard time trying to set the BACK button for any view controllers that are pushed. I'm using segue's and the view controller shows as expected. However I want to change the name of the navigation bar and back button dynamically and placed this in my ViewWillAppear:

    self.title = @"Select Songs";
    [self.backButton setTitle:@"Add"];

更改了导航栏的标题,但后退按钮仍显示被推送窗口的名称,而不是文本添加".

changes the title of the navigation bar but the back button still displays the NAME of the pushed window rather than the text "Add".

模拟指标都是推断的.我还在 Xcode 中的视图下方的黑色托盘中添加了一个 BarButtonItem,并将视图控制器的 backButton 连接到 backButton,但文本仍然没有出现.

The Simulated Metrics are all Inferred. I also added a BarButtonItem to the black tray below the view in Xcode and wired up the backButton of the viewcontroller to the backButton, yet the text still does not appear.

添加以下日志消息也会产生一些有趣的东西:(但标题栏正在正确更新)

Adding the following log messages also yield something interesting: (and yet the titlebar is updating correctly)

-(void) viewDidAppear:(BOOL)animated {
    NSLog(@"%s %@", __FUNCTION__, self.navigationItem.backBarButtonItem);
    NSLog(@"%s %@", __FUNCTION__, self.navigationController.navigationItem.backBarButtonItem);
}

2012-10-14 15:18:41.835 xxxx[2690:907] -[ViewController viewDidAppear:] (null)
2012-10-14 15:18:41.838 xxxx[2690:907] -[ViewController viewDidAppear:] (null)

推荐答案

返回按钮会显示上一个视图的标题,如果没有设置标题,它会显示'返回'.

The back button will show the title of the previous view and if no title is set it'll show 'Back'.

因此,在您的 prepareForSegue 方法中,您可以在推送下一个视图之前更改当前视图的标题.然后后退按钮将显示您设置的标题.

So in your prepareForSegue method, you can change the title of the current view before the next view is pushed. The back button will then show whatever you set the title to.

这篇关于Storyboard UINavigation 控制器后退按钮文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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