Often I find myself need to dismiss the current modal view controller and then immediately push another view controller (so imagine something sliding down and then sliding right). What is a clever way to do this?
If you attempt to do these two operations all in one go, only the first one is carried out, the second one is ignored.
-(void)dismissThenPush{
[self.navigationController dismissModalViewControllerAnimated:TRUE]; //works
[self.navigationController pushViewController:controller animated:TRUE]; //ignored
}
For the past 12 months, what I do is set some global flag, and have the original controller check for this flag in the viewDidAppear method and then call a pushViewController method. But I'm tired of this hack, there must be a way to do this all in one go from the modal view controller.
I just played around with this. I ended up with this:
You end up with the sliding down and sliding right animations happening at the same time, but I think it looks ok.
Code:
In the original view controller:
- (IBAction)pushModalVC {
ModalViewController *modalVC = [[ModalViewController alloc] init];
modalVC.ownerVC = self;
[self presentModalViewController:modalVC animated:YES];
[modalVC release];
}
In the modal view controller:
- (IBAction)pushSecondVC {
// this could be accessed via a property rather than loading
SecondViewController *secondVC = [[SecondViewController alloc] init];
[self dismissModalViewControllerAnimated:YES];
[ownerVC.navigationController pushViewController:secondVC animated:YES];
[secondVC release];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With