简体   繁体   中英

popToViewController with a specific UITabBarController Tab/View

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;

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM