objective-c – XCODE将方法作为参数传递
发布时间:2020-12-14 18:13:42 所属栏目:百科 来源:网络整理
导读:我不想将方法作为参数传递给另一个方法,因此它知道在结束运行时调用的方法.可能吗? [self bringJSON:(NSString *)_passedValua:(NSObject *)anotherMethod]; 解决方法 正如@Daniel在评论中提到的,你可以使用 selector.基本方案如下: // Method declaration
我不想将方法作为参数传递给另一个方法,因此它知道在结束运行时调用的方法.可能吗?
[self bringJSON:(NSString *)_passedValua:(NSObject *)anotherMethod]; 解决方法
正如@Daniel在评论中提到的,你可以使用
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]; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |