Programmatically switching between tabs within Swift

后端 未结 8 562
伪装坚强ぢ
伪装坚强ぢ 2020-11-30 02:32

I need write some code to switch the view to another tab when the iOS app starts (so, for example, the second tab is shown by default rather than the first).

I\'m ne

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-30 03:37

    Swift 3

    You can add this code to the default view controller (index 0) in your tabBarController:

        override func viewWillAppear(_ animated: Bool) {
            _ = self.tabBarController?.selectedIndex = 1
        }
    

    Upon load, this would automatically move the tab to the second item in the list, but also allow the user to manually go back to that view at any time.

提交回复
热议问题