Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Jeff Hay was totally right in his comment except for one thing. You should do it in the <code>-viewDidAppear:</code> method of the view controller which originally presented the first modal view controller.</p> <p><strong>Example:</strong></p> <pre><code>// MyViewController.h @interface MyViewController : UIViewController { BOOL _shouldPresentSecondModalViewController; } @end </code></pre> <hr> <pre><code>// MyViewController.m @implementation MyViewController - (void)viewDidAppear:(BOOL)animated { if(_shouldPresentSecondModalViewController) { UINavigationController *myNavCon; // Code to create second modal navigation controller [self presentModalViewController:myNavCon animated:YES]; _shouldPresentSecondModalViewController = NO; } } - (void)presentFirstViewController { UINavigationController *myNavCon; // Code to create the first navigation controller _shouldPresentSecondModalViewController = YES; [self presentModalViewController:myNavCon animated:YES]; } @end </code></pre> <p><strong>EDIT:</strong><br> Now, if you want to pass data between the two modal view controllers, you can use a delegate.</p> <pre><code>// FirstModalViewControllerDelegate.h @protocol FirstModalViewControllerDelegate @optional - (void)controller:(FirstModalViewControllerDelegate *)vc shouldShowData:(id)anyType; @end </code></pre> <hr> <pre><code>// MyViewController.h @interface MyViewController : UIViewController &lt;FirstModalViewControllerDelegate&gt; { id _dataToDisplay; } @end </code></pre> <hr> <pre><code>// MyViewController.m @implementation MyViewController - (void)viewDidAppear:(BOOL)animated { if(_dataToDisplay != nil) { UINavigationController *myNavCon; // Code to create second modal navigation controller [self presentModalViewController:myNavCon animated:YES]; [_dataToDisplay release]; _dataToDisplay = nil; } } - (void)presentFirstViewController { UINavigationController *myNavCon; FirstModalViewController *myCon; // Code to create the first modal view controller [myCon setDelegate:self]; myNavCon = [[UINavigationController alloc] initWithRootViewController:myCon]; [self presentModalViewController:myNavCon animated:YES]; [myNavCon release]; } - (void)controller:(FirstModalViewControllerDelegate *)vc shouldShowData:(id)anyType { /* This method will get called if the first modal view controller wants to display some data. If the first modal view controller doesn't call this method, the _dataToDisplay instance variable will stay nil. However, in that case, you'll of course need to implement other methods to, like a response to a Done button, dismiss the modal view controller */ [self dismissModalViewController]; _dataToDisplay = [anyType retain]; } @end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload