Storing protocol/delegation results in the correct Object

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 **/

    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:^{ }]; = holdZoneInfo;
    firstUser.area= holdAreaInfo;

    NSLog(@"first User %@, %@, %@, %@",firstUser.userName, firstUser.password,, 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**/

    NSString * neededZoneStore = zoneField.text;
    NSString * neededAreaStore = areaField.text;

    User * user = [[User alloc] init]; = neededZoneStore;
    user.area = neededAreaStore;

    [self.delegate sendUserInfoBack:self didFinishWithZone: neededZoneStore didFinishWithArea: neededAreaStore];

    [self dismissViewControllerAnimated:YES completion:NULL];

So I need = holdZoneInfo but I'm unable to make this happen


In your SetUp view controller class, declare a user property of the type User. When you alloc/init a SetUp view controller set the user property to the firstUser. When the SetUp view controller calls the delegate method, return the firstUser object.

And let the SetUp view controller fill the User object with data from the user.

// in signUpButton
setUpView.user = firstUser;

Refactor the name of the delegate method:

- (void)setUpViewController:(SetUp *)controller exitedWithUser:(User *)user;

Need Your Help

Write text with JS


I am trying to write Text for Related Results but I want the text to be different for every page, I think it can be done with document.write

Closed Connection: next in java

java jdbc

I have ResultSet Methods which I am closing the Connection in a finallly Block: