views:

72

answers:

2

If I dismiss the the modal VC and present it (or another one) again in less than a certain amount of time, it does not appear. Am I missing something?

+1  A: 

Yes, you can't do that. I'm assuming what you did is something like this:

 [self dismissModalViewControllerAnimated:YES];
 [self presentModalViewController:myNewController animated:YES];

This doesn't work. I don't know exactly why, but it is related to the animations I believe. Your options are to either dismiss the first one without animation, or else wait to present the new one in viewDidAppear of the parent, (or possibly viewDidDisappear for the previous modal view, not sure if that works though).

Alex Gosselin
The reason this doesn't work is because the view controller nils out its reference to the modal vc when the animation is complete. Therefore it doesn't think it has another view controller to present modally anymore. Both of your suggested solutions will work.
Robot K
The answers posted here have a bit more detail about the two approaches. http://stackoverflow.com/questions/3919845/presenting-a-modal-view-controller-immediately-after-dismissing-another/3919870#3919870
Robot K
A: 

You cant dismiss two modal view controllers right after another, aside from what the other poster suggested, you can wait a small amount of time before dismissing the other modal view, for example

[self performSelector:@selector(method) withObject:nil afterDelay:.5];

where the method called just dismisses your other modal view. The snippet of code performs the selector after .5 seconds and can be used when having animation timing problems like the one you describe, to seperate the call times in order for them to execute properly.

Daniel
This is a little dangerous (not much) in that if the dismiss animation takes longer than your delay, your modal vc still won't appear. (And the timings could change with updates to the OS.) Alex's approaches are immune to this problem.
Robot K