Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are MANY ways to do this, and over the time I've been working on iPhone software I've experimented with most of them. Here's one.</p> <p>In your child view controller, you can make a property that is a pointer to the parent view controller. Thusly:</p> <p>ChildViewController.h</p> <pre><code>#import "ParentViewController.h" @interface ChildViewController : UIViewController { ParentViewController *parentViewController; } @property (nonatomic, retain) ParentViewController *parentViewController; </code></pre> <p>ChildViewController.m</p> <pre><code>@implementation ChildViewController @synthesize parentViewController; -(void)dealloc { [parentViewController release]; } </code></pre> <p>When you do the work to instantiate the child and push it onto the nav controller, you can set any variables you want on that child's properties, including setting, say:</p> <pre><code>ChildViewController *child = [[ChildViewController alloc] initWithNib:@"nibName" withBundle:nil]; child.parentViewController = self; [self.navigationController pushViewController:child animated:YES]; [child release]; </code></pre> <p>Then inside the child, you can talk about properties of the parent directly, as they get set by the user in the fields of the child, so...</p> <pre><code>self.parentViewController.dataField = @"My data for an NSString property of the parent view controller!"; </code></pre> <p>Then when you pop the child back off, you'll find that you actually set that data into the <code>.dataField</code> property of the parent view controller.</p> <p>(All code in this answer was typed right in here and is intended as an example only--I make no promises about spelling, syntax, etc. )</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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