Reputation: 937
I have a HomeController that allows a user to log in and register. If the user clicks login, I open a modal view using a segue.
Inside the modal view there is a button that says register. The desired action is to close the login modal view and then open the registration modal view using performSegueWithIdentifier:
- (void)loginControllerDidRegister:(LoginController *)controller sender:(id)sender
{
NSLog(@"loginControllerDidRegister");
[self dismissViewControllerAnimated:YES completion:nil];
[self performSegueWithIdentifier:@"RegistrationSegue" sender:sender];
}
This correctly dismisses the modal view, then it calls performSegueWithIdentifier:
, where I have logging code that shows it is being called just as if I had pressed the register button.
I think the animation of the login modal view disappearing may be interfering with the display of the second modal view. Any ideas on what can be done to fix this?
Upvotes: 2
Views: 5442
Reputation: 1345
If someone has the same question.
- (void)loginControllerDidRegister:(LoginController *)controller sender:(id)sender
{
NSLog(@"loginControllerDidRegister");
[self dismissViewControllerAnimated:YES completion:^{
[self performSegueWithIdentifier:@"RegistrationSegue" sender:sender];
}];
}
Upvotes: 0
Reputation: 4931
you must put the performSegue of your second modal view controller in the completion block of the dismissViewControllerAnimated call. UINavigationController can't handle the presentation when it is still presenting the other modal view controller.
Upvotes: 0
Reputation: 1474
well you need to have your "second modal" vc initiated. this is what the "prepareForSegue:" method does. also you need to override the "perform:" method. this is going to be a bit more complicated than you think. if is helps here is a breakdown of how a segue works...
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender;
gets called and passes in "segue". behind the scenes
- (id)initWithIdentifier:(NSString *)identifier source:(UIViewController *)source destination:(UIViewController *)source;
gets called, and this is where "segue" is created.
the "segue" object has properties of
(NSString *)identifier
(UIViewController *)sourceViewController
(UIViewController *)destinationViewController
with out these a segue can not be performed. these are akin to manually allocating your view controller
SomeViewController *secondView = [SomeViewController alloc] initwithNibName:@"SomeViewController" bundle:nil];
then
[[segue destinationViewController] setModalTransitionStyle:UIModalTransitionStyle(...)];
which is...
secondView.modalTransitionStyle = UIModalTransitionStyle(...);
the (...) would be the "segue" transition selected in the storyboard.
lastly
[[segue sourceViewController] presentModalViewController:destinationViewController animated:YES];
which is just
[self presentModelViewController:secondView animated:YES];
is what makes it all happen. you will basically have to tweak with those under the hood goings on to get what you want working, but it is do-able.
Upvotes: 2