Remove TabBar item in Swift

前端 未结 5 1210
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-06 05:17

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:

5条回答
  •  爱一瞬间的悲伤
    2020-12-06 05:41

    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
        }
    }
    

提交回复
热议问题