Hi I am developing an application in which I supposed to go:
- From
UIViewController
1 toUIViewController
2 - From
UIViewController
2 toUIViewController
3 - From
UIViewController
3 toUIViewController
4 - From
UIViewController
4 back toUIViewController
2
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 UIViewController
4 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 UIViewController
2
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 UIViewController
2 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