How to reset a uinavigationview to display the root controller when user clicks back to it in a tab bar app

女生的网名这么多〃 提交于 2019-12-11 23:35:32

问题


How to reset a uinavigationview to display the root controller when user clicks 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


回答1:


[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..




回答2:


place the code in appdelegate.m

if ([viewController isKindOfClass:[UINavigationController class]]) {
    UINavigationController *nav = (UINavigationController *)viewController;
    [nav popToRootViewControllerAnimated:NO];
}



回答3:


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];
}
}


来源:https://stackoverflow.com/questions/2336907/how-to-reset-a-uinavigationview-to-display-the-root-controller-when-user-clicks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!