Setting default tab in UITabBar in swift

前端 未结 4 790
傲寒
傲寒 2020-12-28 22:57

I\'m almost finished with a project and am working out the last few UI kinks. My app uses a tab bar to navigate and for aesthetic purposes I want the app to open on the last

4条回答
  •  悲&欢浪女
    2020-12-28 23:43

    If you're using UISegue from UIStoryBoard, you can use this in UIViewController where you're performing UISegue

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        let tabBarController = segue.destination as? UITabBarController
        tabBarController?.selectedIndex = 1
    }
    

    or

    class TabBarController: UITabBarController {
    
       override func viewDidLoad() {
           super.viewDidLoad()
           self.selectedIndex = 1
       }
    
    }
    

    this code in your UITabBarController itself.

提交回复
热议问题