Iphone viewcontroller

I am creating an application in which I have to transfer data from 16 UITextFields, store it in an array as a class object and display all objects from this array in others viewController.

How can you transfer data from one viewControllerto another?

+3
source share
6 answers

Suppose you have two view controllers named viewController1and viewController2. Have an instance variable textDataof NSArrayin viewController2. Make sure you have added @propertyand @synthesizeto the variable. Select an array in a initmethod viewController2, and you can pass an array from the first viewController to the second

viewController2.textData = viewController1.textArray;
+2
source

. .

singleton . NSUserDefaults . plist . .

: , Cocoa . iPhone, Cocoa. .

+1

,

secondviewcontroller *obj = [[secondviewcontroller alloc]init];
obj.array = data;
0

. (, FirstViewController) :

NSArray *_fields;

@property:

@property (readonly) NSArray *fields;

.m @synthesize:

@synthesize fields = _fields;

(, SecondViewController) , :

FirstViewController *_controller;

@property(nonatomic, retain) FirstViewController *controller;

.m :

@synthesize controller = _controller;

, . .

FirstViewController *first = [[FirstViewController alloc] init];
SecondViewController *second = [[SecondViewController alloc] init];
second.controller = first;

second.controller.fields UITextField .

0

. , ..

  • , - .
  • . : [[UIApplication sharedApplication] delegate]
  • viewControllers .
  • (NSUserDefaults)
  • (, plist?)
0

- Model-View-Controller. .

I assume that you implement some functions of the wizard. Introduce the new domain object FooWizardStateand pass it along with one view controller to the next. This way you can easily break your first view controller of 16 text fields to say that two controllers with 8 text fields are later, if you need, or require a client.

With this design, you can also easily change the view controllers if you need to redo one step of the wizard for the iPad / iPhone user interface idioms.

0
source

All Articles