各种performSelector:...
方法最多可以处理传递给指定选择器的两个参数。如果我需要传递三个或更多参数,我该怎么办?
4123 次
2 回答
14
您需要为此使用 NSInvocation 类。检查此 SO question以获取有关使用它们的更多详细信息。
于 2011-10-05T12:12:27.210 回答
0
我不喜欢 NSInvocation 方式,它需要太多代码。
如果您想立即执行选择器,这是一种简单而干净的方法:
// Assume we have these variables
id target, SEL aSelector, id parameter1, id parameter2;
// Get the method IMP, method is a function pointer here.
id (*method)(id, SEL, id, id) = (void *)[vc methodForSelector:aSelector];
// IMP is just a C function, so we can call it directly.
id returnValue = method(vc, aSelector, parameter1, parameter2);
于 2016-10-31T09:58:57.370 回答