How would I be able to jump back two steps in a view controller navigation and still preserve the navigation?
I have vc1 which on a touch moves to vc2 and then to vc3. how would I jump to vc1 from vc3 for example?
thanks
How would I be able to jump back two steps in a view controller navigation and still preserve the navigation?
I have vc1 which on a touch moves to vc2 and then to vc3. how would I jump to vc1 from vc3 for example?
thanks
Just a copy but safer approach... try like this
- (void) turnBackToAnOldViewController{
for (UIViewController *controller in self.navigationController.viewControllers) {
if ([controller isKindOfClass:[AnOldViewController class]]) {
//Do not forget to import AnOldViewController.h
[self.navigationController popToViewController:controller
animated:YES];
break;
}
}
}
You can use this -
NSArray *controllers = [self.navigationController viewControllers];
NSLog(@"%@",controllers);
Here you get array of controllers.
int count = [controllers count];
Just pass index and switch wherever you want.
UIViewController *theControllerYouWant = [self.navigationController.viewControllers objectAtIndex:(count - 2)];
[self.navigationController popToViewController:theControllerYouWant animated:NO];
Hope this helps you.Thank you.:)
Please try like this
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY SELF.class.description == %@“,[[VC1 class]description]];
BOOL exist = [predicate evaluateWithObject:[self.navigationController viewControllers]];
if (exist) {
for (id object in [self.navigationController viewControllers]) {
if ([object isKindOfClass:[VC1 class]]) {
[self.navigationController popToViewController:object animated:YES];
}
}
}