Search code examples
iosswiftuitabbarcontrollersegue

How to disable UITabBarController


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

}

Solution

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