UINavigation栏的自定义后退按钮 [英] Customized Back button for UINavigation bar

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

问题描述

我提到了不少线程(如何更改导航栏上后退按钮的标题 NavigationController UINavigationBar后退按钮和其他几个)关于自定义后退按钮中的文本以显示所需的字符串。但是,他们不使用故事板。其中很多都不适用。

I have referred to quite a few threads (How do I change the title of the "back" button on a Navigation Bar , NavigationController UINavigationBar Back Button and few others) on customizing text in back button to show desired string. However, they do not use storyboard. So many of them are not applicable.

为了给你一个背景,我创建了我的观点( view1 view2 )通过故事板,我想使用 view2 上的后退按钮导航到 view1 。我怎么能用IB做这个?

In order to give you a background, I have created my views (view1 and view2) through storyboard and I would like to use a back button on view2 to navigate to view1. How can I do this using IB?

或者,我也尝试将 self.navigationItem.backBarButtonItem.title 设置为 @自定义文字; ,但这不起作用。

Alternatively, I also tried setting self.navigationItem.backBarButtonItem.title to @"Custom text";, but this does not work as well.

有人可以建议我如何更改 view2 <上返回按钮的文本/ code>?谢谢!

Can somebody please suggest how can I change the text of Back button on view2? Thanks!

推荐答案

我找到了解决方案。下面描述的方法将允许您更改后退按钮的文本而不更改父视图控制器的标题。

I found the solution to my question. The method described below will let you change the text of back button without changing the title of the parent view controller.


  1. 打开故事板文件,点击链接连接两个viewControllers。

  2. 打开Utilities面板,然后单击Attributes inspector。

  3. 为storyboard segue提供有意义的标识符。 (为了这个例子,我称之为saveReturn。)按Enter键接受。

  4. 打开父视图控制器的.m文件并插入代码。

  1. Open the storyboard file and click on the link connect the two viewControllers.
  2. Open the Utilities pannel and click on Attributes inspector.
  3. Give storyboard segue a meaningful identifier. (For the sake of this example, I call it saveReturn.) Hit enter to accept.
  4. Open the .m file of the parent view controller and insert the code.

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{

if([segue.identifier isEqualToString:@saveReturn])
{
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@Save& Return样式:UIBarButtonItemStyleBordered target:nil action:nil];
}
`}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"saveReturn"]) { self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Save & Return" style: UIBarButtonItemStyleBordered target:nil action:nil]; } `}

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

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