Reputation: 783
i am working on a navigation based application in the rootviewcontroller i hav a few UITextFields. There is a button on rootviewController, on clicking that button i am changing the view using pushviewcontroller. I want to use values entered in these UItextFields in mapview ie my 2nd view.
PLZ suggest me something.
Upvotes: 0
Views: 142
Reputation: 44633
Use an NSDictionary
object to store the values from the first controller. Say you are using two text fields – textField1 and textField2.
- (void)loadSecondController {
NSDictionary *values = [NSDictionary dictionaryWithObjectsAndKeys:textField1.text, @"textField1", textField2.text, @"textField2", nil];
// Assuming you are using IB files
SecondViewController *controller = [[SecondViewController alloc] initWithNibName:nil bundle:nil];
controller.values = values; // Declare a NSDictionary property 'values' in SecondViewController
[self.navigationController pushViewController:controller animated:YES];
[controller release];
}
Now in SecondViewController
, you can access them as
...
textField1Value = [values objectForKey:@"textField1"];
textField2Value = [values objectForKey:@"textField2"];
...
Upvotes: 1
Reputation: 1579
Before pushing assign the values to the second controller. Say you have to send value of textfield1. Now
secondController.textfield1 = textfield1;
Then do your pushing of controller.
Upvotes: 1
Reputation: 31720
you could pass all the information to your second controller before pushing to navigation stack.
See the pseudo code for your reference :
First:
MyMapController* myController = [MyMapController alloc] initWithValues:Value1,value2,value3,......valuen];
[self.navigationController pushViewController:myController animated:YES];
[myController release];
myController = nil;
Second:
MyMapController* myController = [MyMapController alloc] init];
myController.value1 = value1;
myController.value2 = value2;
myController.value3 = value3;
............
myController.value7 = value7;
myController.value8 = value8;
[self.navigationController pushViewController:myController animated:YES];
[myController release];
myController = nil;
There could be more approach for sending the data,
Upvotes: 1