ios - 在 Swift 中删除 TabBar 项目

标签 ios swift uitabbarcontroller tabbar

我目前正在尝试找到一种方法来在运行应用程序时删除 TabBar 项目,我找到了一种启用或禁用它但没有完全删除它的方法。

为了禁用它,我这样做:

enter image description here

在ViewDidLoad中

if let tabBarItem = self.tabBarController?.tabBar.items?[3] as? UITabBarItem {
            tabBarItem.enabled = false
}

这很好用,但用户仍然可以看到 TabBar 项,我会简单地完全删除它,有什么办法吗?

我想通过 Parse 触发 TabBarItem,如果我将 Parse Data 设置为 true,它应该以其他方式显示它不应该。

最佳答案

您想使用一个数组设置 tabBarControllerviewControllers 属性,在该数组中排除了您不想再拥有的特定 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/

相关文章:

android - react-native handle device "share to"特性 iOS/android

ios - Xcode, swift : How to detect link click and stop redirecting Safari?

swift - 合并相同类型的对象

ios - UITabBar在iOS 7中的行为很奇怪,如何解决?

iphone - UITabBarController 与 viewControllers 利用不同的方向?

ios - IMGLYMainEditorViewController 完成 block 问题

objective-c - 查询 Google 纬度/经度需要很长时间,使得 UIViewController 需要永远加载

iphone - 每次选择选项卡时如何获得相同的 View ?

ios - CallKit com.apple.CallKit.error.calldirectorymanager 错误 1

ios - Swift 中开关盒的穷举条件