How to change initial tab bar selection programmatically

前端 未结 2 1385

Having problems changing the initial tab bar selection on an application (i.e. the middle tab is selected on app launch rather than the leftmost tab). The app uses storyboar

相关标签:
2条回答
  • 2020-12-31 13:49

    Since this is the initial view controller, and is not a subclass, you need to set this in your appDelegate.

    In AppDelegate.m, add the following to your application:didFinishLaunchingWithOptions: method:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        // Override point for customization after application launch.
    
        // Select the left-most tab of our initial tab bar controller:
        UITabBarController *tabBar = (UITabBarController *)self.window.rootViewController;
        tabBar.selectedIndex = 0;
        return YES;
    }
    
    0 讨论(0)
  • 2020-12-31 13:53

    tabBar setSelectedItem: try using this in your viewDidLoad

    0 讨论(0)
提交回复
热议问题