2012-06-04 4 views
4
내가 다른 방법에 매개 변수로 방법을 전달하는 wan't

등의 방법을 통과, 그래서 끝이 실행될 때 호출하는 방법을 알고있다. 가능한가? @Daniel 댓글에서 언급 한 바와 같이XCODE는 매개 변수

[self bringJSON:(NSString *)_passedValua:(NSObject *)anotherMethod]; 
+0

선택기를 사용해 보셨습니까? – Daniel

+0

AFAIK 불가능합니다 – Lefteris

답변

15

당신은 그것에 대해 selector를 사용할 수 있습니다. 기본 구성표는 다음과 같습니다 :

// Method declaration - method accept selector as parameter 
- (void) bringJSON:(NSString *)_passedValua toMethod:(SEL)anotherMethod]; 

// Method call - create selector from method name (mind the colon in selector - it is required if your method takes 1 parameter) 
[self bringJSON:jsonString toMethod:@selector(methodName:)]; 

// Implementation 
- (void) bringJSON:(NSString *)_passedValua toMethod:(SEL)anotherMethod]{ 
    ... 
    if ([target respondsToSelector:anotherMethod]) 
     [target performSelector:anotherMethod withObject:_passedValua]; 
} 
+0

awsome! tks 많이 블라디미르와 다니엘! – 88fsantos

+0

좋은, 명예로운 ... 고맙습니다 친구 :) – abhi