我目前正在尝试找到一种方法来在运行应用程序时删除 TabBar 项目,我找到了一种启用或禁用它但没有完全删除它的方法。
为了禁用它,我这样做:
在ViewDidLoad中
if let tabBarItem = self.tabBarController?.tabBar.items?[3] as? UITabBarItem {
tabBarItem.enabled = false
}
这很好用,但用户仍然可以看到 TabBar 项,我会简单地完全删除它,有什么办法吗?
我想通过 Parse 触发 TabBarItem,如果我将 Parse Data 设置为 true,它应该以其他方式显示它不应该。
最佳答案
您想使用一个数组设置 tabBarController
的 viewControllers
属性,在该数组中排除了您不想再拥有的特定 viewController。
if let tabBarController = self.tabBarController {
let indexToRemove = 3
if indexToRemove < tabBarController.viewControllers?.count {
var viewControllers = tabBarController.viewControllers
viewControllers?.remove(at: indexToRemove)
tabBarController.viewControllers = viewControllers
}
}
关于ios - 在 Swift 中删除 TabBar 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28384321/