I am trying to make one of my tab buttons go to the root using popToRootViewControllerAnimated. My question is: where do I put this code for it to work? I have my tabs created through Interface Builder... do they have to be hard coded for this to work?
Here is the code that I'm looking to use:
[self.navigationController popToRootViewControllerAnimated:YES];
New code in AppDelegate:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
if (viewController = HomeViewController) {
[HomeViewController popToRootViewControllerAnimated:NO];
}
}
Adam - I ended up ditching the subclass idea even though it worked, as there is a much easier method.
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
if ([viewController isKindOfClass:[UINavigationController class]]) {
[(UINavigationController*)viewController popToRootViewControllerAnimated:YES];
}
}
This is the code required. I've uploaded this sample project to play around with. The main points are
<UITabBarControllerDelegate>
protocol. The sample project also shows one way to selectively choose which navigation controllers this occurs with.