简体   繁体   English

如何删除UITabBarItem

[英]How to remove a UITabBarItem

I have a nib with four UIViewControllers each with a UITabBarItem. 我有一个带有四个UIViewControllers的笔尖,每个UIViewControllers带有一个UITabBarItem。 At runtime, based on user options, I need to show or hide one of the UITabBarItems. 在运行时,根据用户选项,我需要显示或隐藏UITabBarItems之一。 I cannot figure out how to remove the UITabBatItem. 我不知道如何删除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. 要删除其中一个,只需从TabBar中获取viewControllers并将其放入NSMutableArray中即可。 Then remove the index you want removed and then set the viewControllers property to this new array of view controllers using 然后删除要删除的索引,然后使用以下命令将viewControllers属性设置为该新的视图控制器数组

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. 获取标签栏控制器的视图控制器,删除要“隐藏”的控制器,然后将标签栏控制器的viewControllers数组设置为此新数组。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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