objective-c – XCODE将方法作为参数传递

我不想将方法作为参数传递给另一个方法,因此它知道在结束运行时调用方法.可能吗?

[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];
}

相关文章

在有效期内的苹果开发者账号(类型为个人或者公司账号)。还...
Appuploader官网--IOS ipa上传发布工具,证书制作工具跨平台...
苹果在9月13号凌晨(北京时间)发布 iOS 16,该系统的设备可...
计算机图形学--OpenGL递归实现光线追踪
Xcode 14打出来的包在低版本系统运行时会崩溃,报错信息是Li...