When starting the application, I have a UITabBarController as the root view controller. For this tab bar I have only 7 ViewControllers. Inside AppDelegate.swift in the application(application:didFinishLaunchingWithOptions:) , if I do this, it works correctly:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // Override point for customization after application launch. self.tabBarController = self.window?.rootViewController as! UITabBarController self.tabBarController.selectedIndex = 2 return true }
This works fine, and the third item on the tab bar is selected when the application starts.
But, when I want to select any item that goes under a more navigation controller (which means any index beyond 3), self.tabBarController.selectedIndex = 5 just doesn't work. The specified operator works in any part after the launch of the application, i.e. If I do self.tabBarController.selectedIndex = 5 inside the viewDidAppear first ViewController, it works; but it does not work during application launch, i.e. in application(application:didFinishLaunchingWithOptions:) . The selected tab bar item remains by default after launch. How can I change the selected index above 3 (which is under moreNavigationController ) when the application starts?
source share