我的tabBar上有一个项目,我实际上不想移动到它的视图控制器,但是当单击该项目时,会发生一些事情(当前视图控制器上会出现一个弹出对话框)。
我当前拥有当前代码:
class TabViewController: UITabBarController, UITabBarControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// tell our UITabBarController subclass to handle its own delegate methods
self.delegate = self
}
// called whenever a tab button is tapped
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
if viewController is PostTabViewController {
... code here ...
}
}
}
此处..code处的代码运行正常,但是仍显示PostTabViewController。我将如何停止它?
答案 0 :(得分:0)
您应该在tabBarController(_, shouldSelect:)
func tabBarController(UITabBarController, shouldSelect: UIViewController) -> Bool {
guard viewController is PostTabViewController else {
return true
}
... code here ...
return false
}