如何禁用 UITabBarController

How to disable UITabBarController

我有一个扩展 UITabBarController 的选项卡和三个选项卡。如何禁止标签页按条件打开?

class Tab: UITabBarController {

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

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

}

你可以做到

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