删除Swift中的TabBar项 [英] Remove TabBar item in Swift
问题描述
我目前试图找到一种删除方法,同时运行应用程序TabBar项目,我找到了启用或禁用它的方法,但没有完成删除它。
对于禁用它我做:
I currently try to find a way to remove while run the app a TabBar Item, i found a way to enable or disable it but not to complete remove it.
For disable it i do:
在ViewDidLoad中
In ViewDidLoad
if let tabBarItem = self.tabBarController?.tabBar.items?[3] as? UITabBarItem {
tabBarItem.enabled = false
}
这很有效但仍然用户可以看到TabBar项目,我只是完全删除它,有没有办法?
This works well but still the user can see the TabBar item and i ll simply complete remove it, is there a way?
我想通过Parse触发TabBarItem,如果我设置解析数据如果它应该显示其他方式它不应该。
I want to trigger the TabBarItem via Parse, if i set the Parse Data to true it should show other way it should not.
推荐答案
你想设置 viewControllers
您的 tabBarController
的属性,其中包含一个数组,其中排除了您不想再拥有的特定viewController。
You want to set the viewControllers
property of your tabBarController
with an array where you excluded the particular viewController that you don't want to have anymore.
if let tabBarController = self.tabBarController {
let indexToRemove = 3
if indexToRemove < tabBarController.viewControllers?.count {
var viewControllers = tabBarController.viewControllers
viewControllers?.remove(at: indexToRemove)
tabBarController.viewControllers = viewControllers
}
}
这篇关于删除Swift中的TabBar项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!