I have a view hierarchy with multiple UINavigationControllers
Now from a particular view controller, I wanted to pop to window.rootviewcontroller
How can I do that?
I tried
[UIApplication sharedApplication].keyWindow.rootViewController popToRootViewController];
But it does not work. Please suggest.
Please note I want to go to window.rootVC.
THis will not work for me
[self.navigationController popToRootViewControllerAnimated:YES];
Just get the window instance and set the root view controller again, as popToRootViewController
only pops to root view controller of particular navigation stack
- (void)popToRoot
{
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
UIWindow *mainWindow = appDelegate.window;
ViewController *viewControllerObj = [ViewController new];
UINavigationController *navigationObject = [[UINavigationController alloc] initWithRootViewController:viewControllerObj];
[mainWindow setRootViewController:navigationObject];
}
Hope this helps.
set
UINavigationController *navController = (UINavigationController*)self.window.rootViewController;
[self.navigationController popToRootViewControllerAnimated:YES];