LilMoke
LilMoke

Reputation: 3444

How to remove a UITabBarItem

I have a nib with four UIViewControllers each with a UITabBarItem. At runtime, based on user options, I need to show or hide one of the UITabBarItems. I cannot figure out how to remove the UITabBatItem.

Does anyone know how to do this?

Thanks

Upvotes: 1

Views: 1231

Answers (3)

XJones
XJones

Reputation: 21967

Christian's code is close. It should be:

NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:myTabBarController.viewControllers];
[viewControllers removeObjectAtIndex:indexToRemove];
[myTabBarController setViewControllers:viewControllers];

Upvotes: 2

Jamie
Jamie

Reputation: 5112

To remove one, you can just get the viewControllers from the TabBar and put them in an NSMutableArray. Then remove the index you want removed and then set the viewControllers property to this new array of view controllers using

setViewControllers:animated:

Hoep this helps.

Upvotes: 1

Christian
Christian

Reputation: 1714

Get the tab bar controller's view controllers, remove the one you want to 'hide' and then set the tab bar controller's viewControllers array to this new array.

NSMutableArray *viewControllers = [myTabBarController viewControllers];
[viewControllers removeObjectAtIndex:indexToRemove];
[myTabBarController setViewControllers:viewControllers animated:YES];

Upvotes: 0

Related Questions