Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

maxm007

macrumors newbie
Original poster
Jul 8, 2008
2
0
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

macrumors member
Jul 12, 2008
31
0
Seattle
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

macrumors member
Jul 17, 2008
44
0
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

macrumors 68040
Sep 2, 2008
3,114
93
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

macrumors newbie
Dec 7, 2009
5
0
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

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
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

macrumors newbie
Dec 7, 2009
5
0
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

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
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:
Code:
[appDelegate.firstModalViewController dismissModalViewControllerAnimated:YES];
This should dismiss all the other eight modal views on the stack above it, as well.
 

smcbride15

macrumors newbie
Dec 7, 2009
5
0
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):

Code:
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

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
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):

Code:
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

macrumors newbie
Dec 7, 2009
5
0
Perfect! Using the navigation controller to do it all was a much more intelligent way of doing things. Thanks!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.