i've a login view presented as a ModelViewController and i have a register view presented as a NavigationControlloer on top of it:
Login (ModelViewController) ---->Register(NavigationController)
i'm presenting the Register view(CreateAccount) at the Loginview as follow:
createAccount= [[CreateAccount alloc] initWithNibName:@"CreateAccount" bundle:nil];
navController = [[UINavigationController alloc] initWithRootViewController:createAccount];
UIBarButtonItem *cancelButtun=[[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(HideMe)];
UIBarButtonItem *registerButtun=[[UIBarButtonItem alloc]initWithTitle:@"Register" style:UIBarButtonItemStyleBordered target:self action:@selector(Register)];
createAccount.navigationItem.leftBarButtonItem = cancelButtun;
createAccount.navigationItem.rightBarButtonItem=registerButtun;
createAccount.title=@"Create Account";
[self presentModalViewController:navController animated:YES];
the login controller has the NSURLConnectionDelegate for booth the login and the register. when registration finishs i simply call the
[self dismissModalViewControllerAnimated:YES];
which will dismiss the registration view only.
i want to dismiss the login view also so i can go back to my main application.
Calling dismissModalViewController
will, if the current view controller did not present any modal controllers, call the method on its parent instead. Calling the method on a view controller will dismiss all presented modal view controller to that controller. To illustrate:
If you have three view controllers: vc1, vc2 and vc3 and vc1 is the main/currently used view controller.
In vc1 you present modal vc2. In vc2 you then call dismiss, because there are no modal vcs presented from vc2, the dismiss message is passed to the parent (vc1) which dismisses vc2, and you're back at vc1.
In vc1 you present modal vc2, then from vc2 present modal vc3. Calling dismiss in vc3 will send the message to its parent (vc2) which will dismiss vc3. To dismiss vc2 and vc3 at the same time, you need to call dismiss in vc1, this will dismiss all (both) modal view controllers. If dismissing animated, only the first one will be animated.
One of the best ways to solve this is to use a navigation controller through-out. i.e. instead of using modalViews initially to present login view, use navigationViewcontroller
there itself. If you need to present registration page. Push that view. If you need to goto the initial view (i.e. apart from loginView or registrationView), then use popToRootViewControllerAnimated
method in navigationViewcontroller
.