gpt4 book ai didi

iphone - @selector 有多个参数

转载 作者:太空狗 更新时间:2023-10-30 03:46:17 25 4
gpt4 key购买 nike

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

我有以下内容

[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

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];

关于iphone - @selector 有多个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4555252/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com