简体   繁体   中英

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

Christian's code is close. It should be:

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

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.

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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM