Reputation: 741
How do you perform selectors with an argument? This is my code:
SEL methods=NSSelectorFromString([arrayWithMethods objectAtIndex:i]);
[self performSelector:methods withObject:self afterDelay:MAN_SPEED*i];
If my selector method has an argument, how do I specify it?
Upvotes: 1
Views: 200
Reputation: 23390
The string for a selector with zero arguments looks like this:
arrayWithMethods = [NSArray arrayWithObjects:@"myMethod", ... nil]
If it has one parameter, specify that by adding a colon after the method name:
arrayWithMethods = [NSArray arrayWithObjects:@"myMethod:", ... nil]
Now your myMethod will get passed 'self' (since that's what you're passing as the 'with object".
Upvotes: 6
Reputation: 54619
If it has only one argument you can pass it with the parameter withObject:
if it has more than 1 argument, your going to need a wrapper object to pass it with the same parameter.
Upvotes: 4