I have an application where I need to remove one view from the stack of a UINavigationController and replace it with another. The situation is that the first view creates an
If you want to show any other view controller by popToRootViewController then you need to do following:
UIViewController *newVC = [[WelcomeScreenVC alloc] initWithNibName:@"WelcomeScreenVC" bundle:[NSBundle mainBundle]];
NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:[[self navigationController] viewControllers]];
[viewControllers removeAllObjects];
[viewControllers addObject:newVC];
[[self navigationController] setViewControllers:viewControllers animated:NO];
Now, all your previous stack will be removed and new stack will be created with your required rootViewController.