self.navigationController.tabBarController.selectedIndex not working

前端 未结 7 2080
野趣味
野趣味 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 02:45

    If you are presenting a new controller (different from the one that's currently on screen) you should set the index in the completion block of the function to present your view controller. If you set it before it's presented, it may not work.

    In my case I've embedded the tab controller inside a nav controller. I present the new nav controller newNavContoller, and once it's presented I set the index in my tab controller tvc:

    currentViewController?.presentViewController(newNavController, animated: true, completion: {tvc.selectedIndex = selectedIndex})
    

提交回复
热议问题