Developer/iOS

[iOS] 콜백 메소드 만들기/호출하기

블로blow 2011. 6. 16. 09:56
728x90

<< 콜백 메소드를 호출하는 쪽 >>


@interface CustomObject : NSObject

{

id target;

SEL selector;

}


- (void)setDelegate:(id)aTarget selector:(SEL)aSelector;


- (void)setDelegate:(id)aTarget selector:(SEL)aSelector

{

self.target = aTarget;

self.selector = aSelector;

}


// 콜백 메소드를 호출함

if(target)

{

[target performSelector:selector withObject:result_obj];

}


...


<< 콜백 메소드를 호출 당하는 쪽 >>


[custom_obj setDelegate:self Selector:@selector(CallBackMethod:)];


- (void)CallBackMethod:(id)result_obj

{

// 작업 처리

}


728x90