Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide an item in the tabBar?

i currently have a number of viewControllers that have a relationship with my tabBarController through Storyboard. Given certain setting, i would like to programatically make a certain viewController hidden or visible. I can hide the whole tabBar, but thats not what i'm after. I have been playing in Xcode and scouring interwebs, but can't find a solution. something along the lines of below that doesn't work me!

[[self.tabBarController.tabBar.items objectAtIndex:2] setHidden:YES];
like image 499
veggyaurus Avatar asked Jan 14 '14 05:01

veggyaurus


2 Answers

Used similar code to fix the problem.

NSMutableArray *newTabs = [NSMutableArray arrayWithArray:self.tabBarController.viewControllers];
[newTabs removeObjectAtIndex: 3];
[newTabs removeObjectAtIndex: 2];
[self.tabBarController setViewControllers:newTabs];
like image 105
veggyaurus Avatar answered Nov 17 '22 20:11

veggyaurus


It turns out you can do it in one line:

tabBarController?.viewControllers?.remove(at: 1)

Assume that 1 is the index of the item you want to remove.

like image 41
Jake3231 Avatar answered Nov 17 '22 20:11

Jake3231