我wan't傳遞一個方法作爲參數傳遞給另一種方法,因此它知道端部運行時調用的方法。可能嗎?XCODE傳遞一個方法作爲參數
[self bringJSON:(NSString *)_passedValua:(NSObject *)anotherMethod];
我wan't傳遞一個方法作爲參數傳遞給另一種方法,因此它知道端部運行時調用的方法。可能嗎?XCODE傳遞一個方法作爲參數
[self bringJSON:(NSString *)_passedValua:(NSObject *)anotherMethod];
由於@丹尼爾在評論中提到,您可以使用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];
}
您是否嘗試過使用選擇器? – Daniel
AFAIK這是不可能 – Lefteris