简体   繁体   中英

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.

    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. First paste in your custom code and then call [super popViewControllerAnimated:animated] at the end.

I have verified that this still works fine in SDK 4.3.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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