ios - How can I detect programmatically (egIBAction) when the tab selection changes views?
问题描述
我正在使用 Swift 5。我希望能够以编程方式检测何时单击选项卡栏项以选择不同的 ViewController。理想的情况是能够为选项卡项选择设置 IBAction 事件。虽然我可以为标签栏项目建立一个出口,但我似乎找不到为该项目设置 IBAction 的方法。有没有办法做到这一点?
解决方案
将 UITabBarControllerDelegate 添加到您的 tabBarViewContriller 然后使用此功能。
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
print("last selected index = \(lastSelectedIndex)") //show last index
print("selected index = \(selectedIndex)") //show current selection index
}
推荐阅读
- vue.js - 在 SublimeText 编码时自动导入 VueJs 组件
- flutter - 我一直在使用反向地理编码 api,然后我得到了这个错误?
- python - 循环并通过 for 循环将值添加到数组
- module - 有没有办法在 nim 中编写导入时排除的模块测试函数
- linux - Git 子模块的 gitlink 条目在哪里?
- c - getchar 的奇怪行为,这是实现定义的行为吗?
- ios - 如何将 ios 源依赖添加到 Flutter 插件?
- c# - 如何调试由 StrongNamer 分配了强名称的程序集?
- matlab - Simulink 中的全局变量不刷新
- c# - C#中的抽象方法参数逆变?