Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 8, 2008, 02:40 AM   #1
maxm007
macrumors newbie
 
Join Date: Jul 2008
[iPhone] Cannot display two Modal View Controller after each other

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.
maxm007 is offline   0 Reply With Quote
Old Jul 12, 2008, 03:02 PM   #2
DenNukem
macrumors member
 
Join Date: Jul 2008
Location: 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.
DenNukem is offline   0 Reply With Quote
Old Sep 17, 2008, 09:09 AM   #3
lawicko
macrumors member
 
Join Date: Jul 2008
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
lawicko is offline   0 Reply With Quote
Old Sep 17, 2008, 09:25 AM   #4
PhoneyDeveloper
macrumors 68030
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
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.
PhoneyDeveloper is offline   0 Reply With Quote
Old Dec 7, 2009, 02:08 PM   #5
smcbride15
macrumors newbie
 
Join Date: Dec 2009
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?
smcbride15 is offline   0 Reply With Quote
Old Dec 7, 2009, 02:52 PM   #6
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Quote:
Originally Posted by smcbride15 View Post
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?
__________________
dejo is online now   0 Reply With Quote
Old Dec 8, 2009, 06:49 AM   #7
smcbride15
macrumors newbie
 
Join Date: Dec 2009
Quote:
Originally Posted by dejo View Post
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
smcbride15 is offline   0 Reply With Quote
Old Dec 8, 2009, 08:49 AM   #8
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Quote:
Originally Posted by smcbride15 View Post
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.

Quote:
Originally Posted by smcbride15 View Post
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.
__________________
dejo is online now   0 Reply With Quote
Old Dec 10, 2009, 06:53 AM   #9
smcbride15
macrumors newbie
 
Join Date: Dec 2009
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];

Last edited by kainjow; Dec 10, 2009 at 10:18 AM. Reason: code tags
smcbride15 is offline   0 Reply With Quote
Old Dec 10, 2009, 10:29 AM   #10
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Quote:
Originally Posted by smcbride15 View Post
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.

Quote:
Originally Posted by smcbride15 View Post
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?

Quote:
Originally Posted by smcbride15 View Post
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:?
__________________
dejo is online now   0 Reply With Quote
Old Dec 10, 2009, 02:10 PM   #11
smcbride15
macrumors newbie
 
Join Date: Dec 2009
Perfect! Using the navigation controller to do it all was a much more intelligent way of doing things. Thanks!
smcbride15 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Modal view controller presenter problem moonman239 iPhone/iPad Programming 4 Mar 6, 2014 04:47 PM
Resolved: How do I make a modal view controller's presenter do something when the MVC is done? moonman239 iPhone/iPad Programming 5 Mar 4, 2014 02:07 PM
Resetting a Modal View every time it's opened gwelmarten iPhone/iPad Programming 9 Sep 21, 2012 12:35 PM
How to create a Modal View Programmatically (and dismiss it) roeik iPhone/iPad Programming 10 Aug 15, 2012 02:36 PM

Forum Jump

All times are GMT -5. The time now is 11:32 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps