0

I have a Tab that extends the UITabBarController and three tabs. How can disable a tab from opening by condition?

class Tab: UITabBarController {

override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {

        if(item.tag == 1) // dont open tab  ????
    }

}
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • 1
    Possible duplicate of [Swift disable tab bar item with function](https://stackoverflow.com/questions/50617250/swift-disable-tab-bar-item-with-function) – Kamran Sep 26 '19 at 12:09

1 Answers1

0

You can do

class Tab: UITabBarController , UITabBarControllerDelegate{

    override func viewDidLoad() {
       super.viewDidLoad()
       self.delegate = self
    }
    func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
        return true / false // according to vc type 
     }
}
Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87