I have an Iphone application in which i have 3 tabitems with a tabbarcontroller.Inside the tabbarcontroller each viewcontroller is a navigation controller.when selecting the second tab i have a view controller.when selecting a button on that i am pushing another view controller to the self.navigation controller.and in that viewcontroller i am pushing and go like that.But the problem is when i am selecting the tabitem again that pushedviewcotrooller is shown there.but i need that rootview there again when i am selecting the tab,i tried like this in my code but not worked,`
-(void)tabBarController:(UITabBarController *)tabbBarController didSelectViewController:(UIViewController *)viewController
{
if(tabBarController.selectedIndex==0)
{
//[viewController.tabBarItem setImage:[UIImage imageNamed:@"pinboard_hvr.png"]];
}
else if (tabBarController.selectedIndex==1)
{
NSLog(@"%@",viewController);
//[viewController.tabBarItem setImage:[UIImage imageNamed:@"pinboard_hvr.png"]];
// NSArray *array = [viewController.navigationController viewControllers];
NSLog(@"%@",array);
// [self.navigationController popToViewController:[array objectAtIndex:0] animated:YES];
[viewController.navigationController popToRootViewControllerAnimated:YES];
//[appdelegate.navigationController popToRootViewControllerAnimated:YES];
}
else if (tabBarController.selectedIndex==2)
{
//[viewController.tabBarItem setImage:[UIImage imageNamed:@"pinboard_hvr.png"]];
}
}
`i have tried both with poping to root and also by taking the array of view controllers,but not worked.Can anybody help me to achieve this?
Me too had a similar problem which I solved by the following code.
Hope this helps you.