How do I set selected tab in UITabBarController using StoryBoard?

前端 未结 10 1531
一整个雨季
一整个雨季 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 00:58

    Alexander, I think your problem is getting correct instance of your tab bar. If your tab bar is your root view controller, then you can do it like this in your appdelegate if didFinishLoading method:

    UITabBarController *tabBar = (UITabBarController *)self.window.rootViewController;
        [tabBar setSelectedIndex:3];
    

    Give it a try and tell me the result please.

提交回复
热议问题