简体   繁体   English

如何修改iPhone上默认“后退”按钮的目标?

[英]How can I modify the target of the default Back button on iphone?

I want to have the default shape of the back button, but that makes my program enter a loop at some point. 我想使用后退按钮的默认形状,但这会使我的程序在某个时候进入循环。 The code is this for modifying the text of the back button, written before the initialization of the view. 该代码用于修改返回按钮的文本,该文本在视图初始化之前编写。

UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle: @"Back" style: UIBarButtonItemStyleBordered target: nil action: nil];

[[self navigationItem] setBackBarButtonItem: newBackButton];

[newBackButton release];

can I also change the target to another view? 我也可以将目标更改为其他视图吗? I really need that default shape and I don't know how else to get it. 我确实需要该默认形状,但我不知道该如何获得它。 Thanks! 谢谢!

UINavigationController无法以这种方式工作,您需要使用image创建一个自定义UIBarButton

If you want to customize the right-button in the navigation controller you usually set the backBarButtonItem on the parent view controller, ie the one you are going back to. 如果要在导航控制器中自定义右键,通常backBarButtonItem视图控制器上设置backBarButtonItem ,即您要返回的控制器。

    parentViewController.navigationItem.backBarButtonItem =
    [[[UIBarButtonItem alloc] initWithTitle:@"Back"
                                      style:UIBarButtonItemStyleBordered
                                     target:nil action:nil] autorelease];

There is a solution to modify the target of the back button on this blog . 有一种解决方案可以修改此博客上的后退按钮的目标。 The key idea is to subclass UINavigationController and override the popViewControllerAnimated: method. 关键思想是子类化UINavigationController并重写popViewControllerAnimated:方法。 First paste in your custom code and then call [super popViewControllerAnimated:animated] at the end. 首先粘贴您的自定义代码,然后在最后调用[super popViewControllerAnimated:animated]

I have verified that this still works fine in SDK 4.3. 我已验证这在SDK 4.3中仍然可以正常使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM