PDA

View Full Version : [iPhone] Cannot display two Modal View Controller after each other




maxm007
Jul 8, 2008, 02:40 AM
Hi,

This is for BETA 7.

Here is a simplified version of my problem.

In my application root view controller , the user presses a 'Start Wizard' button and they get modal view controller A presented which contains a 'Step 1 Complete' button. When that 'Step 1 Complete' button is pressed , ModalVC A dismisses itself and delegates an "I'm done" event to the root view controller , which presents another ModalVC B to the user with a 'Step 2 complete'. So basically imagine a Wizard of Modal View Controllers. Try to make one, it doesn't work.

The problem is that MODALVC B doesn't get displayed. It almost seems that when ModalVC A dismisses itself from the parent , this does not go in effect until the main thread goes back into its message loop for a redraw or something and it ignores the subsequent 'PresentModalViewController : nextcontroller' call.

The only way to make it work is to have 2 buttons ('Do Step 1' and 'Do Step 2') is the root view controller and have the user press them individually. Of course that's not what I want.



DenNukem
Jul 12, 2008, 03:02 PM
There are problems with displaying more than one VC in a row. To work-around the problem, allow your program to spin in the message loop after dismissing first VC. Set up a timer event to pull yourself out of the message loop after 1ms and proceed to next VC.

I accept donations in form of beer. :D

lawicko
Sep 17, 2008, 09:09 AM
I think I know better solution than timers. All you need to do is to present next modal view on top of the first modal view (by calling -presentModalView... on the first modal view controller). Then simply dismiss first modal view and second one view will disappear together with the first one :)

PhoneyDeveloper
Sep 17, 2008, 09:25 AM
You can also use performSelector:withObject:afterDelay to do things like this. Set the delay to 0 or 0.1 or something like that. The perform will then happen very quickly. No timers required.

smcbride15
Dec 7, 2009, 02:08 PM
ok but how do actually dismiss that first modal view from within the 2nd one? the dismiss modal view method only takes in the current modal view, no?

dejo
Dec 7, 2009, 02:52 PM
ok but how do actually dismiss that first modal view from within the 2nd one? the dismiss modal view method only takes in the current modal view, no?
So, are you looking to dismiss the first modal while the second one stays active? So that when the second one is finally dismissed you return to the view that was shown when the first modal was presented?

smcbride15
Dec 8, 2009, 06:49 AM
So, are you looking to dismiss the first modal while the second one stays active? So that when the second one is finally dismissed you return to the view that was shown when the first modal was presented?

Ok so my setup is that I have up to 9 modal views displaying one on top of the other. With the last modal view I would like it to dismiss all the preceding modal views when it is dismissed. Is that possible? Thanks

dejo
Dec 8, 2009, 08:49 AM
Ok so my setup is that I have up to 9 modal views displaying one on top of the other.
9? Wow, that sounds like a lot. I hope the app justifies that many.

With the last modal view I would like it to dismiss all the preceding modal views when it is dismissed. Is that possible?
Yes, it's possible. You just somehow need to find a way for the ninth modal view to know about the first modal view. I'd suggest setting it as an ivar in the appDelegate. Then you can call:[appDelegate.firstModalViewController dismissModalViewControllerAnimated:YES];
This should dismiss all the other eight modal views on the stack above it, as well.

smcbride15
Dec 10, 2009, 06:53 AM
Thanks for replying. The thing is that I don't have 9 unique modal views. Its just the same view controller being presented in modal form each time. Maybe I should have a unique modal view for each one...

Here's how I call it from within each modal window. (AddViewController is what gets presented in the modal view):

if(avController == nil)
avController = [[AddViewController alloc] initWithNibName:@"AddView" bundle:nil];

if(addNavigationController == nil)
addNavigationController = [[UINavigationController alloc] initWithRootViewController:avController];

[self.navigationController presentModalViewController:addNavigationController animated:YES];

dejo
Dec 10, 2009, 10:29 AM
The thing is that I don't have 9 unique modal views. Its just the same view controller being presented in modal form each time.It won't matter whether the views are unique or not. What matters is that they all are sitting on the modal view stack.

Maybe I should have a unique modal view for each one...
If they're all the same view, why wouldn't you want to reuse them?

Here's how I call it from within each modal window. (AddViewController is what gets presented in the modal view):

if(avController == nil)
avController = [[AddViewController alloc] initWithNibName:@"AddView" bundle:nil];

if(addNavigationController == nil)
addNavigationController = [[UINavigationController alloc] initWithRootViewController:avController];

[self.navigationController presentModalViewController:addNavigationController animated:YES];
This looks funky. If you are using a UINavigationController, why do you need to present modal views when you could just be pushing the new views onto the navigation stack, via pushViewController:animated:?

smcbride15
Dec 10, 2009, 02:10 PM
Perfect! Using the navigation controller to do it all was a much more intelligent way of doing things. Thanks!