ios – 以编程方式更改tabBar项目?

前端之家收集整理的这篇文章主要介绍了ios – 以编程方式更改tabBar项目?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
用户登录或不登录时,我想更改TabBar项目.

例如:我有5个不同的tabBar项目,都创建了一个Storyboard.

现在我想在用户没有帐户的情况下更改带有索引2(或标签== 2)的tarBar.我想加载一个不同的rootViewController. rootViewController不是我的TabBar的一个项目,我会加载一个完全不同的控制器.

做这个的最好方式是什么?我可以简单地用以下方法更改图标:

self.tabBar.items![0].selectedImage = UIImage(named: "icon_cal_grey")

但是如何更改rootViewController?

我应该在这做吗?

override func tabBar(tabBar: UITabBar,didSelectItem item: UITabBarItem) {

    if item.tag == 1 {
        // ?
    }

}

或者应该生成一个UINavigationController作为RootViewController,并在这里加载“正确的”ViewController作为RootViewController?

解决方法

检查用户是否已登录,然后更改UITabBarController的视图控制器:
tabbarController.viewControllers?.replaceRange()

这也许有助于Set view controllers of UITabBarController in Swift

原文链接:https://www.f2er.com/iOS/327785.html

猜你在找的iOS相关文章