1

I'm trying to change the text of the back button from within Interface Builder, but when I select the Navigation Bar and go into the Attributes Inspector and set the Back Button text to "Close" it still shows up with the title of the previous view.

How do I get this to work?

Baub
  • 5,004
  • 14
  • 56
  • 99

3 Answers3

6

The back button will always show the previous UIViewController title or backBarButtonItem defined.

So if you have "view1" and move to "view2" you need to set the backButton in "view1" so it's displayed correctly while "view2" is presented.
(In other word "view1" is responsible to provide what should be displayed in a back button that point to it)
In this way if "view1" is follow by any views all those will have the correct back button.

Vincent Bernier
  • 8,674
  • 4
  • 35
  • 40
  • I've been able to set the back button via Interface Builder before, but it's not working. – Baub Nov 03 '11 at 19:24
  • Got it! I was able to set it in IB in View 1 and it worked just as you described. I was thinking about it in the wrong way. Thanks so much! – Baub Nov 03 '11 at 19:32
  • 1
    It's confusing the 1st time, it's not what you would expect, but once you figure out why it's like this it make a lot of sense. – Vincent Bernier Nov 03 '11 at 19:52
1

Try this in -(void)viewDidload, as this method is fired after the nib has loaded:

UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Close" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backBarButtonItem;
[backBarButtonItem release];
Alex
  • 8,801
  • 5
  • 27
  • 31
0

A quick and dirty trick is to set the "title" to what name you want in the button in the willDisappear override in the view controller. Make sure to set the "title" back to the correct name on the willAppear override view controller. One drawback with this technique is that on slower units you can see it change. On iPhone 4 and later it's hardly noticeable.

Hope this helps.

Rob
  • 4,149
  • 5
  • 34
  • 48