开发者

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 re开发者_如何学Pythonally need that default shape and I don't know how else to get it. Thanks!


The UINavigationController does not work that way, you'll need to make a custom UIBarButton with an image.


If you want to customize the right-button in the navigation controller you usually set the backBarButtonItem on the parent view controller, i.e. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜