如何在 performSelector: withObject:afterDelay 的Object里传入多个参数

来源:互联网 发布:windows pe u盘版 iso 编辑:程序博客网 时间:2024/05/25 20:00
写代码的时候可能会遇到如下的问题
一个方法

- (voidfooFirstInput:(NSString*first secondInput:(NSString*second
{

}

有两个或者多个参数
当需要执行performSelector方法并且afterDelay的时候,withObject只能传入一个参数,并且也没有对应的withObjects方法,
这么写是不对的。会报错
[self performSelector:@selector(fooFirstInput:secondInput:) withObject:@"first"withObject:@"second" afterDelay:15.0];


遇到这种情况利用如下的一个小方法可以满足调用多个参数的select method
1.
- (void) callFooWithArray: (NSArray *) inputArray{    [self fooFirstInput: [inputArray objectAtIndex:0] secondInput: [inputArray objectAtIndex:1]];}- (void) fooFirstInput:(NSString*) first secondInput:(NSString*) second{}

2.
[self performSelector:@selector(callFooWithArray) withObject:[NSArrayarrayWithObjects:@"first", @"second", nil] afterDelay:15.0];

0 0