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?

cyclingIsBetter
  • 17,447
  • 50
  • 156
  • 241

3 Answers3

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];
 }
rakeshNS
  • 4,227
  • 4
  • 28
  • 42
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];
GoZoner
  • 67,920
  • 20
  • 95
  • 145
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.)

Ankit Srivastava
  • 12,347
  • 11
  • 63
  • 115