@selector有多个参数

jar*_*ryd 5 iphone objective-c selector

如何使用多个参数调用@selector方法?

我有以下内容

[self performSelector:@selector(changeImage:withString:) withObject:A1 withObject:fileString2 afterDelay:0.1];
Run Code Online (Sandbox Code Playgroud)

但得到一个

无法识别的选择器发送到实例

错误

我打电话的方法如下

-(void) changeImage: (UIButton *) button withString: (NSString *) string
{
[button setImage:[UIImage imageNamed:string] forState:UIControlStateNormal];
}
Run Code Online (Sandbox Code Playgroud)

Jil*_*ouc 18

您应该使用NSInvocation

NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:
                             [self methodSignatureForSelector:@selector(changeImage:withString:)]];
[invocation setTarget:self];
[invocation setSelector:@selector(changeImage:withString:)];
[invocation setArgument:A1 atIndex:2];
[invocation setArgument:fileString2 atIndex:3];
[NSTimer scheduledTimerWithTimeInterval:0.1f invocation:invocation repeats:NO];
Run Code Online (Sandbox Code Playgroud)