Hi I am developing an application in which I supposed to go:
- From
UIViewController1 toUIViewController2 - From
UIViewController2 toUIViewController3 - From
UIViewController3 toUIViewController4 - From
UIViewController4 back toUIViewController2
I am using UINavigationController. When I use [self.navigationController pushViewController:VC2 animated:NO]; and [self.navigationController popViewControllerAnimated:NO]; everything works fine.
But when I use [self.navigationController popToViewController:VC2 animated:NO]; from UIViewController4 application terminates saying Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Tried to pop to a view controller that doesn't exist.'
Following is my code how I am popping to UIViewController2
for (UIViewController *vc in self.navigationController.viewControllers) {
if ([vc isKindOfClass:[ViewController2 class]]) {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
ViewController2 *VC2 = [storyboard instantiateViewControllerWithIdentifier:@"ViewController2"];
[self.navigationController popToViewController:VC2 animated:NO];
}
}
When I printed navigation array it shows UIViewController2 in stack.
I have added UINavigationController from Editor->embed in->Navigation Controller
Can anyone please tell me why this is happening? I tried to search for this issue but nothing is helpful