1

I have an application which has a UITabbarController with only One TabBarItem in it i.e. "Home".

Now the problem is while I am in my Home Tab bar Item Can i Add More TabbarItem's with different ViewControllers to my existing UITabbarcontroller.

Here is more elaborated example:

I have only One "Home Tab". I called a service on Home Tab and then server said there must also be ViewController1 and ViewController2 available on the TabBar. Then can I create it on run time. If Yes can any one describe how!

Thanks

Kanan Vora
  • 2,124
  • 1
  • 16
  • 26
Shah
  • 4,990
  • 10
  • 48
  • 70

2 Answers2

1
   NewViewController* vc1 = [[NewViewController alloc] init];

   vc1.tabBarItem.image = [UIImage imageNamed:@"icon.png"];
   vc1.tabBarItem.title = @"Title";

   NSMutableArray* controllers = [NSMutableArray arraywithArray :tabBarController.viewControllers];
   [controllers addObject:vc1];
   tabBarController.viewControllers = controllers;

Hope this helps

DivineDesert
  • 6,924
  • 1
  • 29
  • 61
1

You have to create a new NSMutableArray with a copy of the existing views, then tack your new view on the end and set the Tab Controller views to be the new copy. So if you're in your existing 'single' ViewController:

ViewController *newView = [[ViewController alloc]init];
NSMutableArray *views = [NSMutableArray arrayWithArray:self.tabBarController.viewControllers];
[views addObject:newView];
self.tabBarController.viewControllers = views;
Will Jenkins
  • 9,507
  • 1
  • 27
  • 46