Question

I am using popToViewController method to pop to a view controller. What I was trying to achieve is to pop to an UITabBarController's specific index.

NSArray *viewArrays = [self.navigationController viewControllers];

So my view hierarchy is;

<LoginViewController: 0x6b75850>,
<UITabBarController: 0x6ba0b50>,
<RequestViewController: 0x684fe90>,
<ApplyViewController: 0x6845790>

Following code does pops to my UITabBarController, but since I was on the third view of my UITabBarController, it pops back to the third view

[[self navigationController] popToViewController:[self.navigationController.viewControllers objectAtIndex:1]  animated:YES];

What I want is to pop to the second view of my UITabBarController.

Edit (Answer)

As stated, we don't push or pop. So in order to gather your tabBarController you either use;

UITabBarController *myTabController = [self.navigationController.viewControllers objectAtIndex:indexOfYourTabBarControllerInYourNavigationController];
myTabController.selectedIndex = indexToGo;

or if you are on one of your tabBarController views;

self.tabBarController.selectedIndex = indexToGo;
Was it helpful?

Solution

In UITabBarController you dont pop and push, if you want to go to the second view you would set the selected index instead

Like so

yourTabController.selectedIndex = 1;

Or if the current view controller is a part of the tabBarController do

self.tabBarController.selectedIndex = 1;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top