Reputation: 11201
my app is a Tab based application, in some of the tabs there are navigation controller.
If I navigated in the view, and when I'm in the second view (in the navigation) and change the tab, when I click again the tab, it starts on the second view as I finished.
So, what I want, is when changing the tab,the
popToRootViewControllerAnimated:
effect. So, I will always starts on the first view.
How can I do this?
Thanks!
I add some code to my project following Bart Whiteley's answer, my MainTab.h:
#import <UIKit/UIKit.h>
@interface MainTab : UITabBarController <UITabBarControllerDelegate,UITabBarDelegate>
@end
MainTab.m:
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"this class is loaded");
self.tabBarController.delegate = (id)self;
[self setDelegate:self];
}
-(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
NSLog(@"changing tab");
if ([viewController isKindOfClass:[UINavigationController class]]) {
[(UINavigationController*)viewController popToRootViewControllerAnimated:YES];
}
}
SOLVED! I edit my post with the code
Thanks!
Upvotes: 0
Views: 167
Reputation: 1426
Set a delegate for the UITabBarController, and implement this delegate method:
-(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
if ([viewController isKindOfClass:[UINavigationController class]]) {
[(UINavigationController*)viewController popToRootViewControllerAnimated:YES];
}
}
Upvotes: 1