Skip to content


Adding tabs during runtime #10

cannyboy opened this Issue · 4 comments

2 participants


Is there a way to add tabs during runtime? With UITabBarController, I can do something like this

NSArray *existingTabs = self.tabBarController.viewControllers;
NSMutableArray *mut = [[NSMutableArray alloc] initWithArray:existingTabs];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"iPhone" bundle:[NSBundle mainBundle]];
self.extraViewController = [[ExtraViewController alloc] init];
self.extraViewController = [storyboard  instantiateViewControllerWithIdentifier:@"ExtraViewController"];
[mut addObject:self.extraViewController];
[self.tabBarController setViewControllers:mut animated:YES];

However, I can't get this working with NGTabBarController, when I change the last line above to :

[self.tabBarController setViewControllers:mut]; // no animated

.. I get this exception:

-[NSNull addTarget:action:forControlEvents:]: unrecognized selector sent to instance

.. on this line in NGTabTabController, within the method setTabBarItems

[item addTarget:self action:@selector(handleItemPressed:) forControlEvents:UIControlEventTouchDown];

I got round the problem by hiding and un-enabling the ng_tabBarItem when the tab bar is initially created:

self.extraViewController.ng_tabBarItem.hidden = YES;
self.extraViewController.ng_tabBarItem.enabled = NO;

.. and then showing / enabling when neccesary.


Hi @cannyboy , I'm curious to hear more about your method. I have an application with an NGTabBarController, and I need to be able to basically redraw the tabbar on the fly in various instances. Can you give me a little more detail about how you went about adding new tabs after the NGTabBarController was already presented?


@amsoell I was not able to add new tabs after it was created.
As mentioned above, all I did was hide the ng_tabBarItem when I created the tab bar. When I needed to see it, I just un-hid the item. Since I created the tab bar in my app delegate I first defined a shortcut to my AppDelegate in AppDelegate.h

#define sharedAppDelegate (AppDelegate *) [[UIApplication sharedApplication] delegate]

I also made the vertical tab bar controller a property, as well as the 'hidden' extra view controller

Within AppDelegate.m I had this method:

- (void)showHiddenTab
     self.extraViewController.ng_tabBarItem.hidden = NO;
    self.verticalTabBarController.selectedIndex = self.verticalTabBarController.viewControllers.count-1; // switch to last one

.. which I could call from any other view controller like so:

#import "AppDelegate.h"
// In a buttons action:
[sharedAppDelegate showHiddenTab];

Thanks, @cannyboy. Not the answer I was hoping for, but I appreciate your time! @myell0w, I would love to know if there is a good / preferred way to update the tabs in an NGTabBarController dynamically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.