Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change title of navigationItem Title based on selected Tab Bar Item

Tags:

ios

iphone

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.

like image 221
Per Larsen Avatar asked Jan 03 '13 01:01

Per Larsen


3 Answers

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!

like image 29
JRG-Developer Avatar answered Oct 02 '22 07:10

JRG-Developer


On every tab selection you can change title.

   - (void)tabBarController:(UITabBarController *)tabBarController 
     didSelectViewController:(UIViewController *)viewController
    {
      viewController.title=@"your title"
    }
like image 24
Prince Kumar Sharma Avatar answered Oct 02 '22 05:10

Prince Kumar Sharma


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";
like image 65
Bryan P Avatar answered Oct 02 '22 06:10

Bryan P