I've created a User class with a User object allocated in the first view controller. While in the first view controller, a few of the objects properties are filled with some data. I'm using a second view controller to obtain additional user information and then send it back to the first view controller to store in the remaining object properties. I'm using a protocol and delegation to get this done. I followed the instructions here: Passing Data between View Controllers
Looks like I did everything correctly, except i don't know how to associate the results with the properties of my object. It would be nice to be able to return to the original method in the first view controller that calls the second view controller. Is this possible? A lot of the answers I'm seeing are requiring global variables, but I'm not sure if thats necessary for my case.
/**Implementation of Main View Controller **/
-(IBAction)signUpButton
{
User * firstUser = [[User alloc] init];
firstUser.userName = userNameField.text;
firstUser.password = passwordField.text;
/**second view controller **/
SetUp *setUpView = [[SetUp alloc] initWithNibName:Nil bundle:Nil];
setUpView.delegate = self;
[self presentViewController:setUpView animated:YES completion:^{ }];
firstUser.zone = holdZoneInfo;
firstUser.area= holdAreaInfo;
NSLog(@"first User %@, %@, %@, %@",firstUser.userName, firstUser.password, firstUser.zone, firstUser.area);
/**username and password display fine, but zone and area are null since the delegation operation hasn't been completed as this point **/
}
/**Protocol Method Declared in Main View Controller**/
-(void) sendUserInfoBack: (SetUp *) SetUpController didFinishWithZone:(NSString*)item1 didFinishWithArea:(NSString*) item2
{
holdZoneInfo = item1;
holdAreaInfo = item2;
NSLog(@"Delegation result: %@ %@", holdZoneInfo, holdAreaInfo);
/**This displays correctly**/
}
/**Second view controller implementation file**/
-(IBAction)goToMainView:(id)sender
{
NSString * neededZoneStore = zoneField.text;
NSString * neededAreaStore = areaField.text;
User * user = [[User alloc] init];
user.zone = neededZoneStore;
user.area = neededAreaStore;
[self.delegate sendUserInfoBack:self didFinishWithZone: neededZoneStore didFinishWithArea: neededAreaStore];
[self dismissViewControllerAnimated:YES completion:NULL];
}
So I need firstUser.zone = holdZoneInfo but I'm unable to make this happen