Connect to a UIViewcontroller on a UITabBarController page

I have a binding problem, I use xib, not a storyboard.

I have a UITabBarController system and several other view controllers that sit separately from the tab system. My question is: can I link one of the view controllers using the button back to a specific page in the UITabBarController?

+4
source share
1 answer

UITabBarController is the parent, and ViewControllers under the tabs are children. You can access the TabBarController from childViewControllers using the parentViewController property.

So, if you have a UITabBarController with 2 tabs that contain ViewController1 and ViewController2, you can use this line in any of them.

UITabBarController* tabBarController = (UITabBarController*)self.parentViewController; // So if for example you have a button in ViewController2 and you need to show // ViewController1 when it is pressed, you can do the following tabBarController.selectedIndex = 0; 
+1
source

Source: https://habr.com/ru/post/1445517/


All Articles