2

I need to hide a button on the tab bar, but still have it accessible by code as needed. I know I can completely remove the button, but then I cannot access that view anymore.

So in my case, I want my home screen to be visible when the app first loads, but do not want the tab to show up for it. If they navigate away from that screen, I will add a custom "home" button in the navigation bar at the top.

However, if I remove the tab bar item, I no longer go to the home screen anymore but to what was originally the 2nd tab. Is there a way to only hide the tab bar item and still access it in code?

So you can see how I'm accessing the tab bar to begin with, here is how I can remove the tab bar item.

UITabBarController *tabVC = (UITabBarController *)self.window.rootViewController;

NSMutableArray *tabBarViewControllers = [NSMutableArray arrayWithArray:[tabVC viewControllers]];
[tabBarViewControllers removeObjectAtIndex:0];
[tabVC setViewControllers:tabBarViewControllers];

//or to just disable it

NSArray *tbItems = tabVC.tabBar.items;
UITabBarItem *item_0 = [tbItems objectAtIndex:0];
[item_0 setEnabled:NO];
James
  • 3,765
  • 4
  • 48
  • 79

1 Answers1

-1

There is an option of hiding the bottom TabBar in the attributes inspector "Hide bottom bar on push"

You might find this link useful How to hide/show tab bar of a view with a navigation bar in iOS?

Community
  • 1
  • 1
Joydeep Sarkar
  • 113
  • 1
  • 9
  • Thanks, but I'm not looking to hide the tab bar, only a tab bar item. I need the tabs, I just want to hide the first tab. – James Mar 01 '16 at 12:27