【发布时间】:2019-04-12 22:02:50
【问题描述】:
因此,以编程方式从 UITabBarController 中的一个选项卡切换到另一个选项卡很容易...
self.tabBarController?.selectedIndex = 1
...但是每次对标签索引进行硬编码似乎很不优雅。例如,如果重新排序选项卡,则会导致问题。
有没有办法检索特定 UIViewController 的 [first] 索引,以便代码更像以下内容?
if let destinationIndex = self.tabBarController?.index(of: ExampleViewController) {
self.tabBarController?.selectedIndex = destinationIndex
}
【问题讨论】:
-
在什么情况下标签索引会被重新排序?
-
例如开发者的设计变更。
标签: ios swift uiviewcontroller uitabbarcontroller