I'm working with the Xcode Utility template. In rootViewController.m there's a section that sets up the navbar for what's called the FlipSideView:
(snip)
UINavigationItem *navigationItem = [[UINavigationItem alloc] initWithTitle:@"Title"];
(snip)
How can you programmatically change the navbar title from within the FlipsideViewController class? I tried:
self.navigationItem.title = @"XXXXXX";
w/o success.
OK, I spent some time on this, because I want to use the convenience of NIB layout for the utility-template app, but I want to be able to internationalize without maintaining a gazillion nibs.
So, the first thing is to add to the FlipViewController class:
IBOutlet UINavigationBar *navBarItself;
Then, in IB, to control-drag from the Navigation Bar to the File's Owner, and connect to navBarItself in the File's Owner.
Then, the code:
- (void) viewWillAppear:(BOOL) animated {
[super viewWillAppear:animated];
navBarItself.topItem.title = @"Peace!!";
}
and this appears to work like a charm
(and it also works when added to ViewDidLoad)
(p.s. the other answers shown here did not work for me)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With