How to bounce two steps on the controller timeline?

How can I go back to the two steps in navigating the controller and still save the navigation?

I have vc1, which by touch goes into vc2, and then in vc3. how can i switch to vc1 from vc3 for example?

thanks

+4
source share
6 answers

try it

    - (IBAction)back{
if(self.navigationController.viewControllers.count>2)
    [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count-3] animated:YES];
}
+3
source

Just a copy, but a safer approach ... try 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;
        }
    }

}
+2
source

-

NSArray *controllers = [self.navigationController viewControllers];
NSLog(@"%@",controllers);

.

int count = [controllers count];

, .

UIViewController *theControllerYouWant = [self.navigationController.viewControllers objectAtIndex:(count - 2)];
[self.navigationController popToViewController:theControllerYouWant animated:NO];

, . .:)

+1

, - .

.

 NSArray *viewControllers = self.navigationController.viewControllers;
 self.navigationController.topViewController = viewControllers[i];

where I can be any vc available from the stack controllers.

0
source

You must try

NSArray *vcArray = [[self navigationController] viewControllers];
[self navigationController popToViewController:[vcArray objectAtIndex:vcArray.count-3] animated:YES];
0
source

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];
        }
    }
}
0
source

All Articles