1

I have a UITabBarController with two UIViewControllers f.e "All Messages", "Favourite Messages".

For some action I need dynamically replace my UITabBar items with new (Other actions, other images)...

so it should be "Like" and "DisLike" instead of "All Messages", "Favourite Messages".

What is the best way to do it?

// Note
//I don't need ViewControllers for these items, I will use TabBar delegate
//so I can't do following:
tabBarVC.viewControllers = [NSArray ...new view controllers]

Thanks

Injectios
  • 2,777
  • 1
  • 30
  • 50

3 Answers3

0

From the UITabBarController docs

To configure the tabs of a tab bar controller, you assign the view controllers that provide the root view for each tab to the viewControllers property.

What you could do it just momentarily hide the tabBarController's toolbar and create a new UIToolbar in it's place with your options

Paul.s
  • 38,494
  • 5
  • 70
  • 88
0

You can use this code in your tabbarselect method

 if(tabbar.selectedindex==1)
 {
  self.title=@"newtitle"
 }

like this

 UITabBarController *tabbar1 = [[UITabBarController alloc] init];


secondviewcontroller  *second = [[secondviewcontroller alloc] initWithNibName:nil bundle:nil];
second.title=@"message";

firstviewcontroller *third=[[firstviewcontroller alloc]initWithNibName:nil bundle:nil];
third.title=@"all message";

   if(tabbar1.selectedindex==0)
 {
 second.title=@"like";
  third.title=@"DisLike";
 }

tabbar1.viewControllers = [NSArray arrayWithObjects: second,third,nil]; 
tabbar1.view.frame=CGRectMake(0, 0, 320, 460);
[self.view addSubview:tabbar1.view];
vishiphone
  • 750
  • 7
  • 14
0

This example shows removing the current tabbar item selected.

NSMutableArray* newArray = [NSMutableArray arrayWithArray:self.tabBarController.viewControllers];
[newArray removeObject:self];
[self.tabBarController setViewControllers:newArray animated:YES];

Make the changes to the tabbar items array and call setviewcontrollers

TheTiger
  • 13,264
  • 3
  • 57
  • 82
sujith1406
  • 2,822
  • 6
  • 40
  • 60