I'm working on this project where I have a User class, my main view controller, and my SetUp control viewer (second control viewer). The User class has all the User properties, the main view controller creates the username/password then calls the SetUp view controller, and the SetUp view controller allows the user to enter additional information. I created a protocol in my SetUp view controller that calls a delegate method in my main view controller, after the user enters the additional information in the second view controller. The delegate methods returns a User object, but this is where I get lost. Where is the User object being returned? Its definitely not going where I want it to.
/**Main View Controller Implementation**/
#import "BWViewController.h"
#import "User.h"
@interface BWViewController ()
@end
@implementation BWViewController
@synthesize holdPassword,holdUserName,holdZone,holdArea;
-(IBAction)signUpButton
{
firstUser = [[User alloc] init];
firstUser.userName = userNameField.text;
firstUser.password = passwordField.text;
SetUp *setUpView = [[SetUp alloc] initWithNibName:Nil bundle:Nil];
setUpView.delegate = self;
User * bufferUser;
bufferUser = [self presentViewController:setUpView animated:YES completion:^{ }]; /**This is where I want the User object from the delegate method return to**/
}
/**Delegate method in Main view controller**/
-(User*) sendUserInfoBack: (SetUp *) SetUpController didFinishWithZoneInfo:(NSString*)zoneInfo didFinishWithAreaInfo:(NSString*) areaInfo
{
User*holdUser;
holdZone = zoneInfo;
holdArea = areaInfo;
holdUser.userZone = holdZone;
holdUser.userArea = holdArea;
return holdUser; /**return this to bufferUser object in method above**/
}
/**Second View controller Interface**/
#Import "User.h"
@class SetUp;
@protocol SetUpControllerDelegate <NSObject>
-(User*) sendUserInfoBack: (SetUp *) SetUpController didFinishWithZoneInfo:(NSString*)zoneInfo didFinishWithAreaInfo:(NSString*) areaInfo;
@property (weak,nonatomic) id<SetUpControllerDelegate>delegate;
@end
/**Second View controller implementation**/
-(IBAction)goToMainView:(id)sender
{
NSString * neededZoneStore = Zone.text;
NSString * areaStore = Area.text;
User * user = [[User alloc] init];
user.userZone = neededZoneStore;
user.userArea = neededAreaStore;
[self.delegate sendUserInfoBack:self didFinishWithZoneInfo:neededZoneStore didFinishWithAreaInfo:neededAreaStore];
[self dismissViewControllerAnimated:YES completion:NULL];
}
@protocol SetUpControllerDelegate <NSObject>Sure. I'm trying to return a User object with the variables obtained in the SetUp view controller into the bufferUser object in my main view controller.