IOS: dismiss two viewController
Asked Answered
M

3

6

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?

Monroemonroy answered 18/4, 2012 at 15:59 Comment(1)
how second view is added to first view?Fong
A
15

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];
 }
Alcala answered 18/4, 2012 at 17:16 Comment(0)
E
5

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];
Everrs answered 18/4, 2012 at 16:9 Comment(1)
I think the animated parameters should be NO then YES, see rakeshNS 's answerFiddlededee
I
0

This happens coz viewDidAppear is called everytime before the view appears so as soon as it appears you dismiss it and it disappears..

I don't think what u are trying to do can be achieved with modalViewControllers... instead use a navigationController and keep adding your viewcontrollers onto the stack and when you want to goto the First view controller just call

 [self.navigationController popToRootViewControllerAnimated:YES];    

EDIT:

just thought of it this can be achieved by using delegation.. you make second the delegate of third and as soon you dismiss the thirdviecontroller send the delegate a message.In this message call [self dismissModalViewControllerAnimated:NO];.. and you are done.. (pretty easy if you know delegation.)

Irate answered 18/4, 2012 at 16:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.