我的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。我将如何停止呢?
最佳答案
您应该在tabBarController(_, shouldSelect:)
中进行检查
func tabBarController(UITabBarController, shouldSelect: UIViewController) -> Bool {
guard viewController is PostTabViewController else {
return true
}
... code here ...
return false
}
关于ios - 防止tabBar移动到下一个View Controller onselect,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51387348/