我正在尝试实时检测用户选择的选项卡。例如,如果用户选择0 th
索引,同时我想让用户选择了zeroth
索引选项卡。所以为此,我用了tabbarcontroller
委托方法如下。
override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
print("the selected index is : \(selectedIndex)")
}
但这显示了以前的视图控制器。作为一个例子,我认为second tab
然后我选择first tab
然后这将索引打印为2
.那么我怎样才能获得正确选择的选项卡。
希望您对此提供帮助。
您可以获得所选的索引UITabBarItem
通过从项目数组中获取该特定项目的位置UITabBar
。试试这个
override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
print("the selected index is : \(tabBar.items.index(of: item))")
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)