//// FirstView
액션이 일어남에 따라 핸들링이 있는 부분.
클래스에 델리게이트 선언
액션이 일어나는 클래스의 델리게이션 멤버에 self 대입.
//// SecondView
액션이 일어나는 부분
프로토콜 선언
델리게이트 멤버를가짐
//// First View
// h
#import "SecondViewController.h"
@interface ViewController : UIViewController<SecondViewDelegate>
// m
- (IBAction)btnAction:(id)sender {
SecondViewController *secondViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondView"];
secondViewController.delegate = self;
[self.navigationController pushViewController:secondViewController animated:YES];
}
//// SecondView
///h
@protocol SecondViewDelegate
@required
-(void)done:(NSString *)str;
@end
@interface SecondViewController : UIViewController
@property (strong, nonatomic) id<SecondViewDelegate> delegate;
///m
- (IBAction)btnAction:(id)sender { // btnAction이 핸들링 될때, 델리게이트의 메소드 호출
[self.delegate done:self.tf.text];
[self.navigationController popViewControllerAnimated:YES];
}