更改后退按钮的标题
我需要将导航控制器中后退按钮的默认标题值更改为其他值。
我正在尝试使用以下代码:
UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle: @"Terug" style: UIBarButtonItemStyleBordered target:nil action:nil];
self.navigationItem.backBarButtonItem = newBackButton;
[newBackButton release];
我也尝试过:
UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle: @"Terug" style: UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = newBackButton;
[newBackButton release];
我在 viewDidLoad 的末尾使用此代码。
我可以使用以下代码创建一个普通按钮(方形):
UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle: @"Terug" style: UIBarButtonItemStyleBordered target:nil action:nil];
self.navigationItem.leftBarButtonItem = newBackButton;
[newBackButton release];
该解决方案的问题是我需要创建一个单独的方法来弹出视图控制器。另一个问题是按钮的形状,我需要一个箭头形状的按钮。
你有什么想法吗?
I need to change the default title value of the back button in a navigationcontroller to something else.
I am trying this with the following code:
UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle: @"Terug" style: UIBarButtonItemStyleBordered target:nil action:nil];
self.navigationItem.backBarButtonItem = newBackButton;
[newBackButton release];
i also tried:
UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle: @"Terug" style: UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = newBackButton;
[newBackButton release];
I am using this code at the end of the viewDidLoad.
I am able to create a normal button (square) with the following code:
UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle: @"Terug" style: UIBarButtonItemStyleBordered target:nil action:nil];
self.navigationItem.leftBarButtonItem = newBackButton;
[newBackButton release];
The problem with this solution is that I need to create a seperate method that pop's the view controller. Another issue would be the shape of the button, I need an arrow shaped button.
do you have any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想要一个自定义后退按钮,您需要创建一个新按钮并为其分配一个新选择器。
backBarButtonItem 不可编辑,因此需要设置 leftBarButtonItem。
这是创建自定义后退按钮的方法
这是模拟后退按钮的选择器
If you want to have a custom back button you need to create new one and assign a new selector to it.
The backBarButtonItem is not editable, so you need to set the leftBarButtonItem.
This is how you can create a custom back button
And this is the selector to simulate the back button
有一个简单的解决方案,
假设您要从 viewA 移动到 viewB
在从 viewA 移动到 viewB 之前,更改 viewA 的标题,
例如:
There is a simple solution
lets say you are moving from viewA to viewB
just before moving from viewA to viewB change the title of viewA
for example:
从“viewDidLoad”方法调用此按钮。
[或者,使其成为“实用程序”类的类方法,并在需要的每个 viewContorller 中将其作为类方法调用。]
另外,不要忘记实现“backAction”,如下所示:
快乐编码!
Call this button from your 'viewDidLoad' method.
[Or, make it a class method of a 'Utitlity' class and call it as a class method in each viewContorller it is required.]
Also, don't forget to implement the 'backAction', something like this:
Happy coding!