저는 User 클래스, 주 뷰 컨트롤러 및 SetUp 컨트롤 뷰어 (두 번째 컨트롤 뷰어)가있는이 프로젝트에서 작업하고 있습니다. User 클래스에는 모든 User 속성이 있으며 기본보기 컨트롤러는 사용자 이름/암호를 만들고 SetUp보기 컨트롤러를 호출하며 SetUp보기 컨트롤러는 사용자가 추가 정보를 입력 할 수있게합니다. 사용자가 두 번째보기 컨트롤러에 추가 정보를 입력 한 후 주보기 컨트롤러에서 대리자 메서드를 호출하는 프로토콜을 SetUp보기 컨트롤러에 만들었습니다. 대리자 메서드는 User 객체를 반환하지만, 이것은 내가 잃어버린 곳입니다. User 객체는 어디에서 반환됩니까? 그것은 확실히 내가 원하는 곳으로 가지 않습니다.대리자 및 프로토콜을 사용하여 개체를 반환하는 방법
/**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];
}
가능한 한 간단하게 무엇을하려고하는지 명확히하려고 할 수 있습니까? – nhgrif
'@protocol SetUpControllerDelegate' 확실히. SetUp보기 컨트롤러에서 얻은 변수를 사용하여 User 개체를 주보기 컨트롤러의 bufferUser 개체로 반환하려고합니다. –
Brosef