7
votes

enter image description hereI have a Tab Bar View Controller that has four possible view controllers. My main tab bar view that all the other views have a relationship too has a navigation bar that i can double click on and change the title in my storyboard. What i need to know is how to changed the title of this navigation item based on the selected tab bar item.

For instance i will have four tabs. 1 is "Bills", 2 is "Groceries", 3 is "Gas", and 4 is "Personal". I want the title of my view to be Bills if the "Bills Tab is selected and so on.

EDIT: Hopefully this will clarify what i'm trying to accomplish.

I want to be able to change the title of the Navigation Bar at the top of each of the four table Views on the right. The Tab Bar Controller is the only place that I can actually double click and change the tile while is storyboard. I want the title to change based on which table view is selected from the tab bar.

4
Are the "four possible view controllers" each an instance of the same class? Is this where you're wanting to change the title? Or are you wanting to change the title of say a parent view controller? - JRG-Developer
each of the table view controllers with have their own class even through it will be almost the same just loading a different datasource. - Per Larsen
Ok, I've edited my answer. Let me know if this helps. - JRG-Developer

4 Answers

2
votes

Remove any navigation bar item you manually added to the view controller and add this to your viewDidLoad method

self.navigationController.navigationBar.topItem.title = @"My Title";

or

self.navigationController.topViewController.title = @"My Title";
1
votes

You should just be able to set the title property within each of the "four view controllers" like this:

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"Title For View Controller Goes Here";
}

Then, whenever said tab for this view controller is clicked, the navigation bar's title should change to this title.

Edit

It sounds like you may have placed a UINavigationBar object from Interface Builder in your tab bar's view. Instead, you actually want to have the UITabBarController embedded within a UINavigationController.

Go through Ray Wenderlich's tutorial on starting storyboarding, and this should show you how to do this:

http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1

Good luck!

1
votes

On every tab selection you can change title.

   - (void)tabBarController:(UITabBarController *)tabBarController 
     didSelectViewController:(UIViewController *)viewController
    {
      viewController.title=@"your title"
    }
1
votes

I should warn you that this method may be an inelegant hack, because I'm only just beginning to understand navigation myself. But here's how I would approach it:

Basically, you should add a UINavigationItem to each of the UIViewControllers you want to have a title, and change the text of the UINavigationItem depending on which UIViewController is showing.