删除Swift中的TabBar项 [英] Remove TabBar item in Swift

查看:338
本文介绍了删除Swift中的TabBar项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前试图找到一种删除方法,同时运行应用程序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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆