我正在尝试使用 NSInvocation 调用对象上的方法并将其sender
作为参数发送。下面的代码调用了 mthod,但似乎传递给 mthod 的对象并不是真正的 self 对象
- (void)setTarget:(id)taret withAction:(SEL)selector
{
NSMethodSignature *methodSignature = [target methodSignatureForSelector:action];
_invocation = [[NSInvocation invocationWithMethodSignature:methodSignature] retain];
_invocation.target = target;
_invocation.selector = action;
[_invocation setArgument:self atIndex:2];
}
- (void)callTargetWithSender
{
[_invocation invoke];
}