IOS: dismiss two viewController

11,128

Solution 1

You need to dismiss third view controller first and then second Viewcontroller. Do the following code when you want to go first view controller.

-(void)goToFirstView{
        UIViewController *vc = [self parentViewController];
   //     UIViewController *vc = [self presentingViewController]; //ios 5 or later
        [self dismissModalViewControllerAnimated:NO];
        [vc dismissModalViewControllerAnimated:YES];
 }

Solution 2

How is the Third modal view being dismissed in the first place? Perhaps by the user touching a 'Done' button? If so, it is in the handler for the button that you want to dismiss both.

You can dismiss both as:

[self dismissModalViewControllerAnimated: YES];
[self.presentingViewController dismissModalViewControllerAnimated: NO];
Share:
11,128
cyclingIsBetter
Author by

cyclingIsBetter

Updated on June 23, 2022

Comments

  • cyclingIsBetter
    cyclingIsBetter almost 2 years

    I have three viewController

    First, Second and Third

    from Second to open Third I use

    Third *third = [[Third alloc]initWithNibName:@"Third" bundle:nil];
    [self presentModalViewController:third animated:YES];
    [third release];
    

    Now I want return from third to first; then I set in viewDidAppear in second this code:

    [self dismissModalViewControllerAnimated:NO];
    

    but for 1 second I see Second and I don't want watch it...how can I do?

  • onmyway133
    onmyway133 over 10 years
    I think the animated parameters should be NO then YES, see rakeshNS 's answer