Reputation: 5051
Here is the scenario. I have 4 view controllers v1, v2, v3, v4 which are displayed in 4 tabs of iPhone (using UITabbarcontroller). now I push another view sv1 to v1 (while I am viewing v1, I use pushviewcontroller like [appDelegate.nv pushViewController:sv1 animated:YES]). nv is UINavigationController init with rootviewcontroller, v1.
Now if I press v2 tabbar (while I am viewing sv1), and then press v1 I see sv1. However, I do not want this behavior. I want to show v1 instead of sv1. How can I remove sv1 from its parent's view when v2 is clicked?
I have tried using [self.navigationController popToRootViewControllerAnimated:NO]; from viewWillDisappear method of sv1 and it is not working (it goes back to v1 but all messed up, like navigation bar is not drawn and tabbar icon for v1 is not shown, the whole v1 view seems to be broken).
Could anyone let me know how can I fix this problem?
Thanks.
Upvotes: 0
Views: 1052
Reputation: 364
You may read this firstly:
Problem popping to root nav controller on tab bar switch
In additional... UITabBarController
conforms to UITabBarDelegate
where defined
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
you may call popToRootViewControllerAnimated
there, moreover looks like your UINavigationController
for v1 is accessible from appDelegate
Upvotes: 1