如何快速获取 UITabBar 项目的选定索引 我不是在谈论 UITabBarController。
我知道我可以使用 UITabBarItem.tag。
但对我来说,我不能为选定的索引使用标签,因为它已经用于其他目的。 有没有其他方法可以快速获取所选选项卡的索引。
最佳答案
https://developer.apple.com/documentation/uikit/uitabbar
UITabBar 有 2 个属性“items”和“selectedItem”,都是 UITabBarItem 类型。
因此您可以通过获取“items”中“selectedItem”的索引来获取所选项目的索引。
items.index(of: selectedItem)
关于ios - 如何获取 UITABBAR 中选定选项卡的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48075722/