您的位置:首页 > 移动开发 > Objective-C

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

2014-04-11 11:24 399 查看
写代码的时候可能会遇到如下的问题

一个方法

- (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:[NSArray arrayWithObjects:@"first", @"second", nil] afterDelay:15.0];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: