views:

468

answers:

2

I can't just do

[myViewController dismissModalViewControllerAnimated:YES];
[myViewController presentModalViewController:nextModalViewController animated:YES];

one after the other, because then the two animation blocks try to affect the same references simultaneously and things break badly.

So what I need to do is make the latter call only after the first animation has finished. But there's no UIViewControllerDelegate method like didDismissModalViewController. What should I do?

+1  A: 

It's a bit hacky (ok, maybe a lot hacky), but you could simply present the second one after a fixed delay:

[myViewController performSelector:@selector(showSecondModalView) withObject:nil afterDelay:0.5];

(or whatever the animation duration turns out to be).

Daniel Dickison
I agree with this answer, seeing as that apple has not provided a better solution for this
Daniel
Hey, even I had similar problem, and the above solution worked for me..Thanks. I had a query, how to display first->second->again first->again second modal view controllers ?(i.e. 1st and 2nd modal view controllers one after another)
imMobile
+1  A: 

What's wrong with just subclassing the view controller (if you haven't already) and doing this:

 - (void) viewDidDisappear: (BOOL) animated
 {
     [super viewDidDisappear: animated];


     [myViewController presentModalViewController:nextModalViewController animated:YES];
 }

I'm not sure how you are handling your references to the view controllers, but the point I'm trying to make is just catch the viewDidDisappear for the model view controller that is sliding off.

Amagrammer
hey, thanks for the suggestion! this seems to work. the one caveat is that i had to use performSelectorOnMainThread:withObject:waitUntilDone: even though it's already in the main thread, just so that all the internal notifications triggered by the dismissal get cleared out before the new presentModalViewController:animated: call starts mucking around again. Otherwise I get an EXC_BAD_ACCESS.
lawrence