在ios中设置后栏按钮项的标题 [英] set title of back bar button item in ios

查看:161
本文介绍了在ios中设置后栏按钮项的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用故事板,如果我设置了ViewController类的title属性,当我按下SecondViewController时,该字符串将显示为我的后退按钮的文本,我该如何更改?,我想要为后退按钮添加了不同的标题。

I am using storyboards in my application, and if I set the title property of a ViewController class, that string will appear as the text of my back button when I push a SecondViewController, how can I change this?, I want to put a different title for the back button.

我已经使用了这个但它不起作用:

I have used this but it doesn't work:

UIBarButtonItem *btnBack = [[UIBarButtonItem alloc]
                                   initWithTitle:@"Back" 
                                   style:UIBarButtonItemStyleBordered
                                   target:self
                                   action:nil];
    [self.navigationItem setBackBarButtonItem: btnBack];

请帮帮我

推荐答案

试试这个,

Objective-C:

Objective-C:

UIBarButtonItem *btnBack = [[UIBarButtonItem alloc]
                            initWithTitle:@"Done"
                            style:UIBarButtonItemStyleBordered
                            target:self
                            action:nil];
self.navigationController.navigationBar.topItem.backBarButtonItem=btnBack;

Swift:

var btn = UIBarButtonItem(title: "Done", style: .Plain, target: self, action: "backBtnClicked")

self.navigationController?.navigationBar.topItem?.backBarButtonItem=btn

这篇关于在ios中设置后栏按钮项的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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