I have a navigation controller. I first pushed a VC, then presented 12 modals VC\'s. Now I want to pop to root viewController. How can I do that? Please help me out.
Keep a first NavigationController in an instance variable of AppDelegate. In AppDelegate.h
@property (nonatomic, retain) UINavigationController *navigationControllerFirst;
In the RootViewController viewDidLoad add the following.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
app.navigationControllerFirst = self.navigationController;
}
Then, to achieve what you wanted, in the 12th presented modal add the following function to go back to RootViewController.
- (IBAction)GoToHome:(id)sender {
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[app.navigationControllerFirst dismissViewControllerAnimated:YES completion:^{
[app.navigationControllerFirst popToRootViewControllerAnimated:YES];
}];
}