tags:

views:

416

answers:

3

hi, i have normal UIViewcontroller ,inwhich i added UINavigationControllerDelegate,i added as following in willappear?but it did not work?

    [self.navigationController setNavigationBarHidden:NO animated:YES];
    self.navigationController.navigationItem.title = @"hai";
+2  A: 

You should set the title in the view controller you add to your navigation controller.

i.e. in the add view controller

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"My Title";
}

or access the array of your viewcontrollers directly

        AddFriendViewController *addFriendsView = [[AddFriendViewController alloc] initWithNibName:@"AddFriendViewController" bundle:nil];
        [self.navigationController pushViewController:addFriendsView animated:YES];
        [[self.navigationController.viewControllers objectAtIndex:0] setTitle:@"myTitle"];
        [addFriendsView release];
Henrik P. Hessel
A: 

Are you sure that self.navigationController.navigationItem is not nil when you set its title?

Adam Woś
+1  A: 

Every view controller has a navigation item. You are changing the navigation item of the navigation controller... but that will never be seen unless the navigation controller was inside another navigation controller! Instead of

self.navigationController.navigationItem.title = @"hai";

you want

self.navigationItem.title = @"hai";

or, if your navigation item's title is nil, the navigation controller will use your view controller's title:

self.title = @"hai";

You should simply set the view title, which is used by both navigation bars and tab bars, unless you want to specify a different title for each of those for some reason.

benzado