0

I would like to know how to make the UITabBarItem be highlighted when I choose to do so in the program. Is this possible?

THanks

Lilz
  • 4,013
  • 13
  • 61
  • 95

3 Answers3

3

You can change which tab is selected -- which also changes the highlight -- easily:

tabcontroller.selectedIndex = youNewIndexHere;

If your tabcontroller is in the app delegate (which is the case if you used the tab bar application template when you created your project) it would look something like this:

ProjectNameAppDelegate *appDelegate = (ProjectNameAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate tabcontroller].selectedIndex = youNewIndexHere;
Matthew Frederick
  • 22,245
  • 10
  • 71
  • 97
0

tabbar works if you know the index and write it like this:

NSMutableArray *item [[NSMutableArray alloc] init];

[items addObject: [[[UITabBarItem alloc] initAsULike] autorelease]; <--- init as you like here

...

[tabBar setItems:items animated:FALSE];

tabBar.selectedItem = [items objectAtIndex: your_index]; <--- write your index here
[items release];
chikuba
  • 4,229
  • 6
  • 43
  • 75
0

I've got a UITabBar, created in IB but without a TabBarController. In my awakeFromNib I just initialise it to the first item like this:

[self.tabBar setSelectedItem:[[self.tabBar items] objectAtIndex:0]];

Don't forget, the UITabBarDelegate didSelectItem does not get called in this case.

Rob
  • 1,037
  • 1
  • 13
  • 20