1

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!

willcodejavaforfood
  • 43,223
  • 17
  • 81
  • 111
DanielaM
  • 591
  • 1
  • 5
  • 6

3 Answers3

1

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

Community
  • 1
  • 1
christo16
  • 4,843
  • 5
  • 42
  • 53
0

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];
Mike Weller
  • 45,401
  • 15
  • 131
  • 151
0

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.

user8472
  • 3,268
  • 3
  • 35
  • 62