Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have the second view controller presenting itself as modal in this example:</p> <p>In the second view controllers h file:</p> <pre><code>@protocol SecondViewControllerDelegate &lt;NSObject&gt; - (void)addItemViewController:(id)controller didFinishEnteringItem:(NSString *)item; @end @interface SecondPageViewController : UIViewController &lt;UITextViewDelegate&gt; { NSString *previouslyTypedInformation; } @property (weak, nonatomic) IBOutlet UITextView *textView; @property (nonatomic) NSString *previouslyTypedInformation; @property (nonatomic, weak) id &lt;SecondViewControllerDelegate&gt; delegate; </code></pre> <p>In the second view controllers m file make sure to synthesize properties and add then add this:</p> <pre><code>- (IBAction)done:(id)sender { NSString *itemToPassBack = self.textView.text; NSLog(@"returning: %@",itemToPassBack); [self.delegate addItemViewController:self didFinishEnteringItem:itemToPassBack]; //dismiss modal view controller here } </code></pre> <p>Then in the first view controllers h file set it as delegate:</p> <pre><code> @interface FirstPageViewController: UIViewController &lt;SecondViewControllerDelegate&gt; @property (nonatomic) NSString *returnedItem; </code></pre> <p>Then in the first view controller's m file synthesize and add the method:</p> <pre><code>- (void)addItemViewController:(SecondPageViewController *)controller didFinishEnteringItem: (NSString *)item { //using delegate method, get data back from second page view controller and set it to property declared in here NSLog(@"This was returned from secondPageViewController: %@",item); self.returnedItem=item; //add item to array here and call reload } </code></pre> <p>Now you have the text of what was returned! You can add the string to your array in the first view controller's viewDidLoad and call </p> <pre><code>[self.tableView reloadData]; </code></pre> <p>and it should work.</p>
 

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