1
你如何用参数执行选择器?这是我的代码:如何使用参数执行选择器?
SEL methods=NSSelectorFromString([arrayWithMethods objectAtIndex:i]);
[self performSelector:methods withObject:self afterDelay:MAN_SPEED*i];
如果我的选择器方法有一个参数,我该如何指定它?
你如何用参数执行选择器?这是我的代码:如何使用参数执行选择器?
SEL methods=NSSelectorFromString([arrayWithMethods objectAtIndex:i]);
[self performSelector:methods withObject:self afterDelay:MAN_SPEED*i];
如果我的选择器方法有一个参数,我该如何指定它?
与零个参数选择的字符串看起来是这样的:
arrayWithMethods = [NSArray arrayWithObjects:@"myMethod", ... nil]
如果它有一个参数,指定由该方法名称后添加一个冒号:
arrayWithMethods = [NSArray arrayWithObjects:@"myMethod:", ... nil]
现在你myMethod的将会通过'self'(因为这就是你通过'with object'所传递的内容
如果它只有一个参数,你可以用参数withObject:
如果有超过1个论点,您将需要一个包装对象具有相同的参数通过它传递。
或者使用NSInvocation – borrrden 2012-07-15 04:10:58
有['performSelector:withObject:withObject:'](http:// dev eloper.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Protocols/NSObject_Protocol/Reference/NSObject.html#//apple_ref/doc/uid/20000052-BBCGGCBE)用于双参数方法。 – 2012-07-15 04:30:06
是的,我忘了那一个。 – 2012-07-15 14:02:24