Reputation: 21137
When you have a UINavigationController
integrated into one of the Tabs of a UITabBarController
, the UITabBarController
remembers where the user was last time the tab was used. Is it possible to have the UITabBarController forget and always start the tab as if it was the first time?
f.e. structure is a follows
The user starts at Tab1/View1, then he navigates to Tab1/View2. He changes to Tab2/View1 and then presses Tab1:
Upvotes: 2
Views: 94
Reputation: 6323
Try like below it will help you
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
for(int i = 0; i < tabBarController.viewControllers.count; i++) {
if(tabBarController.selectedIndex != i && [[tabBarController.viewControllers objectAtIndex:i] isKindOfClass:[UINavigationController class]])
[[tabBarController.viewControllers objectAtIndex:i] popToRootViewControllerAnimated:NO];
}
}
Upvotes: 3
Reputation: 7410
Have a look at the UITabBar delegate protocole.
Then use tabBarController:didSelectViewController:
that way :
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
if (viewController != tabBarItem1) {
[self.navigationControllerInTab1 popToRootViewControllerAnimated:NO];
}
}
That way, when you leave the first tab item, it will pop the NavigationController
to the rootViewController
.
Upvotes: 1