How to reset a uinavigationview to display the root controller when user clicks back to it in a tab bar app
How to reset a uinavigationview to display the root controller when user click开发者_如何学运维s back to it in a tab bar app
Hey,
Just wondering how I would do this. I have the navcontroller in my delegate along with the tabbar controller and Any time the user clicks to another tab I want the rootview on the navigation controller to be shown if and when they click back the the tab that contains the uinavcontroller.
Does this make sense?
Nick
[self.navigationController popToRootViewControllerAnimated:YES];
Or NO if you don't want it to animate.
This way all the views that were cached are still there, i.e. you don't "remove/release" all the views above the root view, unless the navigationController deems it necessary.
I hope this was what You were looking for..
place the code in appdelegate.m
if ([viewController isKindOfClass:[UINavigationController class]]) {
UINavigationController *nav = (UINavigationController *)viewController;
[nav popToRootViewControllerAnimated:NO];
}
When using the UITabBar delegate method, you must delay the popToRootViewControllerAnimated call.
-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
if ([self.selectedViewController isKindOfClass:[UINavigationController class]]) {
UINavigationController *view=(UINavigationController *)self.selectedViewController;
[view performSelector:@selector(popToRootViewControllerAnimated:) withObject:nil afterDelay:.5];
}
}
精彩评论