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

写代码的时候可能会遇到如下的问题
一个方法

-  ( void fooFirstInput: ( 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];

你可能感兴趣的:(ios)