Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I quickly wrote the following class and showing/hiding tab views from UITabBarController worked like magic:</p> <p>TabBarDesigner.h</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; @interface TabBarDesigner : NSObject { } +(void) setTabBarController:(UITabBarController *)tabBarController items:(NSArray *)tabBarItems viewControllers:(NSArray *)viewControllers; +(void) removeItemsInRange:(NSRange) range; @end </code></pre> <p>TabBarDesigner.m</p> <pre><code>#import "TabBarDesigner.h" static NSArray *_tabBarItems = NULL; static NSArray *_viewControllers = NULL; static UITabBarController *_tabBarController = NULL; @implementation TabBarDesigner +(void) setTabBarController:(UITabBarController *)tabBarController items:(NSArray *)tabBarItems viewControllers:(NSArray *)viewControllers { if (tabBarItems &amp;&amp; viewControllers &amp;&amp; tabBarController) { if ([tabBarItems count] == [viewControllers count]) { [_tabBarItems release]; [_viewControllers release]; _tabBarItems = [tabBarItems copy]; _viewControllers = [viewControllers copy]; _tabBarController = tabBarController; } } } +(void) removeItemsInRange:(NSRange) range { if (_tabBarController) { if ( range.location &lt; ([_tabBarItems count] - 1) ) { if ( (range.length + range.location) &lt; [_tabBarItems count] ) { NSMutableArray *tabBarItems = [_tabBarItems mutableCopy]; [tabBarItems removeObjectsInRange:range]; NSMutableArray *viewControllers = [_viewControllers mutableCopy]; [viewControllers removeObjectsInRange:range]; [_tabBarController setViewControllers:viewControllers]; NSUInteger i; for (i = 0; i&lt; [viewControllers count]; i++) { UIViewController *vC = [viewControllers objectAtIndex:i]; vC.tabBarItem.image = [[tabBarItems objectAtIndex:i] image]; vC.tabBarItem.title = [[tabBarItems objectAtIndex:i] title]; vC.tabBarItem.tag = [[tabBarItems objectAtIndex:i] tag]; } [tabBarItems release]; [viewControllers release]; } } } } @end </code></pre> <p>A sample of how to use this class: In your MyAppDelegate.m</p> <pre><code>#import "TabBarDesigner.h" - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [TabBarDesigner setTabBarController:_tabBarController items:[_tabBarController.tabBar items] viewControllers:[_tabBarController viewControllers]]; // remove the first 3 tabs [TabBarDesigner removeItemsInRange:NSMakeRange(0,3)]; // show all tabs [TabBarDesigner removeItemsInRange:NSMakeRange(0,0)]; // continue with your code } </code></pre> <p>Cheers!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload