views:

45

answers:

2

Hi all, I have a Controller/View for a generic list of items, that can be extended for displaying a custom list.. Listing and navigation works fine.. but I can't change the title of UINavigationController. In the generic Controller:

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.view addSubview: navigationController.view];
}
- (void)setNavigationTitle: (NSString *)title
{
    NSLog(@"set title: %@", title); // this works
    self.navigationController.title = title; // Nothing works here
}

Then, the extended class does..

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setNavigationTitle: @"Custom list"];
}

The navigationBar still have "Item" as title :(

+2  A: 

use

self.title = @"yourTitle";
Gyani
I have now: NSLog(@"set title: %@", title); self.title = title; self.navigationItem.title = title; self.navigationController.title = title; // none of these works :/
grilix
set title in - (void)viewWillAppear:(BOOL)animated method
Gyani
tried everywhere, no case :(
grilix
+2  A: 

In your UIViewController there is a title property and it is that property that will be displayed by the NavigationController. So when pushing a new UIViewController onto the navigation stack set the title of that UIViewController to whatever is appropriate.

In your case it looks like it would be:

[self setTitle:@"WhateverTitle"];
willcodejavaforfood
the first view is not pushed: [self.view addSubview: navigationController.view]; i tried also: self.title = @"AAAA"; [self.view addSubview: navigationController.view]; and does not works
grilix
In the pushed views (when user selects an item), the title is changed correctly
grilix
I notice that you didn't set a rootViewController for navigation controller. The first view controller in navigationController is called rootViewController. You may set its title using self.title = @"xxx".
iPhoney
my navigationbar does not have a "rootViewController" :?
grilix