nickthedude
nickthedude

Reputation: 4973

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

Upvotes: 0

Views: 2178

Answers (3)

Jaswanth Kumar
Jaswanth Kumar

Reputation: 158

place the code in appdelegate.m

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

Upvotes: 1

user3132985
user3132985

Reputation: 291

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

Upvotes: 0

RickiG
RickiG

Reputation: 11390

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

Upvotes: 2

Related Questions