An Example Using A Class
In #ViewController.h that you want to pass data to
#import
@class MyClassName;
@interface #ViewController : UIViewController
{
MyClassName *myClass1;
}
@property (nonatomic, assign) MyClassName *myClass1;
In #ViewController.m that you want to pass data to
//Add import:
#import "MyClassName.h"
//Add synthesize:
@implementation #ViewController
@synthesize myClass1;
//Deal with data:
//********** VIEW WILL APPEAR **********
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[SomeObject setText:[myClass1 someMemberOfMyClassName]];
In #ViewController.m that you are passing data from
//Give view controller a pointer to the possession object in row
[mySub1ViewController setmyClass1:[whatIWantToPass]];
//Display the other view
[[self navigationController] pushViewController: ...
If you want to pass the data back when you close simply use the same set# property functions to store for the other view to read back from
//********** VIEW WILL DISAPPEAR **********
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
//Clear first responders (in case any objects are currently first responder)
[SomeTextField resignFirstResponder];
//Save changes
[myClass1 setSomeMemberOfMyClass1:[SomeTextField text]];
}