0

I've a UINavigationController and in the picture you can see a UIViewController added to it.

Now, I would like to customize the top bar of the UINavigationController with the content of the current visible UIViewController. More in particular, I would like:

  1. add the title
  2. customize "back" button text

Should I use self.navigationController method from the current UINavigationController ? If so, what are the next steps ?

Thanks enter image description here

Black Frog
  • 11,595
  • 1
  • 35
  • 66
aneuryzm
  • 63,052
  • 100
  • 273
  • 488

2 Answers2

2

You can set the Title with:

[[self navigationItem] setTitle:@"title text"];

You can change the backbuttontext in the InterfaceBuilder or:

[[[self navigationItem] backBarButtonItem] setTitle:@"back button text"];

But remember that the backBarButtonItem comes from the previous ViewController so you have to set it there. Alternatively the title is set from the previous view.

n3on
  • 2,051
  • 1
  • 16
  • 16
  • I've found out that it doesn't work in viewWillAppear but only in viewDidLoad. Since my view is appearing, why can't I set it there ? thanks – aneuryzm Apr 27 '11 at 14:54
  • Actually what you say for the button is not correct. I need to replace the button instead of the text to make it work. i.e. https://discussions.apple.com/thread/2508892?threadID=2508892 – aneuryzm Apr 27 '11 at 15:01
  • are you sure that viewWillAppear is called? I tested only with viewDidLoad. But sometimes there are problems with viewWillAppear ( http://stackoverflow.com/questions/131062/iphone-viewwillappear-not-firing ). I tested my code on a sample project and it was working fine. So I'm sure my code is right. – n3on Apr 27 '11 at 15:32
0
self.title = "Your title";

You can use this in the current view controller for displaying title

visakh7
  • 26,380
  • 8
  • 55
  • 69