I have several views that I open one after another modally. View1 calls View2 and View2 calls View3.
I use this code to call the next view:
View2 *myView = [[View2 alloc] initWithNibName:@"View2" bundle:[NSBundle mainBundle]];
[self presentModalViewController:myView animated:YES];
[myView release];
If the user pushes cancel then it goes back one View… 3 to 2 and 2 to 1
[self.parentViewController dismissModalViewControllerAnimated:YES];
What I need to do is when the user is on View3 if they don’t select cancel but complete the operation, then I need to go back to View1 and release View2 and View3.
How do I do that?
EDIT: The MAIN WINDOW has a Navcontroller and 6 view controllers. I call the View 1 like this:
View1 *screen = [[View1 alloc] initWithNibName:@"View1" bundle:[NSBundle mainBundle]];
self.Search = screen;
[mainNavController presentModalViewController:screen animated:YES];
[screen release];
EDIT #2:
Main Windows calls View 1. Main Window has a NavController in the XIB this works:
View1 *screen = [[View1 alloc] initWithNibName:@"View1" bundle:[NSBundle mainBundle]];
[mainNavController presentModalViewController:screen animated:YES];
[screen release];
Then in the XIB on View 1 I added a NavController and tied it to View1NavController in the .h
View 1 then calls view 2:
View2 *myView = [[[View2 alloc] initWithNibName:@"View2" bundle:nil] autorelease];
UINavigationController * navController = [[[UINavigationController alloc] initWithRootViewController:myView] autorelease];
[View1NavController presentModalViewController:navController animated:YES];
When I execute this, no errors, but it doesnt show the View2.
Why don’t you use
UINavigationController? You can use bothpopToRootViewControllerAnimated:andpopViewControllerAnimated:for your purpose.As such if you do,
You should go back to
1.Excerpt from
dismissModalViewControllerAnimated,If you present several modal view controllers in succession, and thus build a stack of modal view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. When this happens, only the top-most view is dismissed in an animated fashion; any intermediate view controllers are simply removed from the stack. The top-most view is dismissed using its modal transition style, which may differ from the styles used by other view controllers lower in the stack.
Using Navigation Controller
For navigation controller to work, instead of where your load your
view1you will do this,This is assuming that
view1was therootViewControllerOnce you’ve the navigation controller set up then you can load
view2like this,In such case,
Cancel
Complete