gpt4 book ai didi

ios - 检测 UITabBarController 的标签栏项目更改

转载 作者:行者123 更新时间:2023-11-28 23:46:05 25 4
gpt4 key购买 nike

有没有办法(例如委托(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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com