tags:

views:

116

answers:

1

hi ,

i have two different view controllers added to the viewcontrollers array of a tabbarcontroller and this tabbarcontroller is added to a navigationcontroller. now i want to show different title for different views in the tabbar, on the navigationController. Pls help me to find a solution for this.... i am new to iPhone app development...

+1  A: 

the title within the navigation bar is taken from the navigation item from it's top view controller. It sounds like its top view controller, in your case, is the tab bar controller, so you'll want to set the title of the tab bar controller whenever the tab bar changes.

Specifically, you'll want to assign a UITabBarControllerDelegate to the tab bar controller's delegate property and implement the following method:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    tabBarController.title = viewController.title;
}

The line is equivalent to

    tabBarController.navigationItem.title = viewController.navigationItem.title;

So you can use either one. Any way, set the titles of the individual tab view controllers to whatever title you want, and then the title will change when the tabs change.

Ed Marty
no i want to change the navigationcontroller title whenever the tab bar changes... how can i do that...
Do exactly what I said
Ed Marty
thanks Ed... with some changes to your code i could now display titles on the navigationcontroller....
Ed..In the above application ..how can i add a done button to the navigation bar from one of the view .... i tried many ways .. likeself.navigationItem.rightBarButton = self.doneButton;but this is not working
Perhaps you should ask a new question for this. However assuming you mean self.navigationItem.rightBarButtonItem, and self.doneButton is a non-null reference to a UIBarButtonItem, how does it not work?
Ed Marty
Ed.... thanks for ur reply...I usedself.navigationController.navigationBar.topItem.rightBarButtonItem = self.doneButton and it worked....but i dont know why it didnt work the other way... do u have any idea...?. can u pls explain me as i am new to iphone app development..
I couldn't tell you exactly what the problem is, but my first gues is that self is not the topviewcontrollerr when that line gets called.
Ed Marty