对于NSInvocation / invoke对,addTarget失败

时间:2015-04-30 16:58:56

标签: ios nsinvocation

我将目标和操作从字典值传递给UIButtons。如果我尝试传递一个NSInvocation / invoke对,这可以正常工作。

//   |self| is a member of |MyClass|, which declares selector |test|

NSDictionary *button1Data = @{ @"selectorString" : NSStringFromSelector(@selector(test)),
                               @"target" : self };

[button1 addTarget:button1Data[@"target"]
            action:NSSelectorFromString(button1Data[@"selectorString"])
  forControlEvents:UIControlEventTouchUpInside];

//  button1 executes target fine

NSInvocation *testInvocation = [NSInvocation invocationWithMethodSignature:[MyClass instanceMethodSignatureForSelector:@selector(test)]];
    testInvocation.selector = @selector(test);
    testInvocation.target = self;
    [testInvocation retainArguments];

NSDictionary *button2Data = @{ @"selectorString" : NSStringFromSelector(@selector(invoke)),
                                       @"target" : testInvocation };

[button2 addTarget:button2Data[@"target"]
            action:NSSelectorFromString(button2Data[@"selectorString"])
  forControlEvents:UIControlEventTouchUpInside];

//  button2 executes gives exceptions

button2的例外情况没有注册转储。

我在俯瞰什么?

0 个答案:

没有答案