如何使用参数执行选择器?

bme*_*nde 1 xcode objective-c selector ios

你如何用参数执行选择器?这是我的代码:

SEL methods=NSSelectorFromString([arrayWithMethods objectAtIndex:i]);
[self performSelector:methods withObject:self afterDelay:MAN_SPEED*i];
Run Code Online (Sandbox Code Playgroud)

如果我的selector方法有参数,我该如何指定它?

Gra*_*rks 6

具有零参数的选择器的字符串如下所示:

arrayWithMethods = [NSArray arrayWithObjects:@"myMethod", ... nil]
Run Code Online (Sandbox Code Playgroud)

如果它有一个参数,请通过在方法名称后添加冒号来指定:

arrayWithMethods = [NSArray arrayWithObjects:@"myMethod:", ... nil]
Run Code Online (Sandbox Code Playgroud)

现在你的myMethod将被传递给'self'(因为那就是你传递的'with object'.