有没有办法(例如委托(delegate))让标签栏 Controller 在您点击某个项目时执行某些操作?
该操作只能在显示 View 时执行一次,而不是在您重复按选项卡按钮时执行一次。
我正在使用这个委托(delegate),但它不能很好地工作,因为每次我触摸选项卡时它都会启动(而不是仅在每次选项卡更改时启动)
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
print("Hey")
}
最佳答案
你可以尝试在 didSelect
旁边实现 shouldSelect
func tabBarController(_ tabBarController: UITabBarController,
shouldSelect viewController: UIViewController) -> Bool {
return tabBarController.viewControllers.index(of:viewController) != tabBarController.selectedIndex
}
关于ios - 检测 UITabBarController 的标签栏项目更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52636646/