xxx.h
@protocol delegate명;
@property(nonatomic, retain) id<delegate명> delegate;
맨 밑에
@protocol delegate명 <NSObject>
- (void)delegate_method:(returnType)variable;
@end
xxx.m
@synthesize delegate=_delegate;
[_delegate release];
- (id)initWithDelegate:(id<delegate명>)delegate {
self = [self init];
if(self) {
[self setDelegate:delegate];
}
}
delegate보낼 method 안에는
if([self.delegate respondsToSelector:@selector(delegate_method명:)]) {
[self.delegate delegate_method명:variable];
}
delegate 구현
- (void)delegate_method:(returnType)variable {
NSLog(@"%@", variable);
}