本文介绍了iPhone - 在UINavigationController上更改Back Button的目标或选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在UINavigationController上按UIViewController时的默认行为是操作系统显示一个后退按钮,再次关闭UIViewController。

The default behaviour when pushing a UIViewController on a UINavigationController is for the OS to display a back button that pops the UIViewController off again.

我想要设置这个后退按钮的一个不同的行为(返回两个屏幕) - 无论如何我可以做到这一点,而无需创建我自己的自定义图形等后退按钮。

I have the desire to set a different behavior for this back button (to go back two screens) - is there anyway I can do this without having to create my own back button with custom graphic etc.

谢谢:)

推荐答案

正如我原先怀疑的那样,这是不可能的任何特别简单的方法。所以在创建任何自定义UIBarButtonItem时也适用相同的方法,只需从Google获取后退按钮图标....

As I half suspected originally, this isn't possible any exceptionally easy way. So same method applies when creating any custom UIBarButtonItem, just have to source the back button icon from Google....

UIButton *backButtonInternal = [[UIButton alloc] initWithFrame:CGRectMake(0,0,54,30)];
[backButtonInternal setBackgroundImage:[UIImage imageNamed:@"backButton.png"] forState:UIControlStateNormal];
boldSystemFontOfSize:12]];
[backButtonInternal addTarget:self action:@selector(backButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *backBarButton = [[UIBarButtonItem alloc] initWithCustomView:backButtonInternal];   
[backButtonInternal release];
[[self navigationItem] setLeftBarButtonItem:backBarButton];
[backBarButton release];

这篇关于iPhone - 在UINavigationController上更改Back Button的目标或选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 01:26