self.navigationController.tabBarController.selectedIndex not working

前端 未结 7 2075
野趣味
野趣味 2021-01-14 02:07

I have a UITabBarController which containing 4 different UIViewControllers.

On first tab there is a UINavigationViewController

7条回答
  •  长发绾君心
    2021-01-14 03:08

    Do the following, before trying to change tab:

    UITabBarController *tab=self.tabBarController;
    
    if (tab){
       NSLog(@"I have a tab bar");
       [self.tabBarController setSelectedIndex:1];
    }
    else{
       NSLog(@"I don't have");
    }
    

提交回复
热议问题