2013年7月16日 星期二

自己做delegate

一,先新建一個yourDelegateProtocol。
@protocol yourDelegateProtocol <NSObject>
-(void)yourMethod:(NSString *)str withTarget:(NSString*)target;
@end


二,在你要送出delegate的class中宣告你要用來呼叫delegate方法的物件
id <yourDelegateProtocol> delegate;


三,在你要使用delegate的class中的.h宣告這個class要遵守delegate
@interface anotherView : UIView <yourDelegateProtocol>

四,在你原本的viewController中執行delegate物件的方法,即可呼叫所有遵守delegate的方法
    [delegate yourMethod:@"hello" withTarget:@"mylover"];

沒有留言:

張貼留言