How do I set selected tab in UITabBarController using StoryBoard?

前端 未结 10 1506
一整个雨季
一整个雨季 2020-12-31 00:38

How can I switch to some tab in UITabBarController using StoryBoard? I have tried the code below but without success (the tab is not selected):

         


        
10条回答
  •  春和景丽
    2020-12-31 01:08

    Here is what I do (Swift 5.x):

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
            if let tabBarController = self.window?.rootViewController as? UITabBarController {
                if let viewControllers: [UIViewController] = tabBarController.viewControllers {
                    tabBarController.selectedIndex = viewControllers.count-1
                }
            }
            return true
        }
    

提交回复
热议问题