@selector有多个参数 [英] @selector with multiple arguments

查看:264
本文介绍了@selector有多个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How does one call an @selector method with multiple arguments?

我有以下

[self performSelector:@selector(changeImage:withString:) withObject:A1 withObject:fileString2 afterDelay:0.1];

但获得


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

unrecognized selector sent to instance

错误

我的方法我打电话如下

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


推荐答案

你应该使用NSInvocation

You should use 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];

这篇关于@selector有多个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆