user347161
user347161

Reputation: 327

Adding title to NavigationBar

I have two different view controllers added to the view controllers array of a TabBarController and this TabBarController is added to a Navigation Controller.

Now I want to show different title for different views in the tabbar, on the navigationController.

Any help would be appreciated.

Upvotes: 2

Views: 1591

Answers (2)

Nikhil Bansal
Nikhil Bansal

Reputation: 1545

Suppose you have three viewcontrollers having three different view and you want to change the title of navigation bar,when you are pushing secondViewcontroller and same when you are thirdviewcontroller then:

viewController2.navigationItem.title = @"Select Template";
viewController3.navigationItem.title = @"Template";

This way we can change the title of navigation bar while pushing some next view controller.

Hope it helps.

Upvotes: 0

Ed Marty
Ed Marty

Reputation: 39690

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.

Upvotes: 2

Related Questions