bmende
bmende

Reputation: 741

How to perform selectors with an argument?

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

Answers (2)

Graham Perks
Graham Perks

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

Matthieu Riegler
Matthieu Riegler

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

Related Questions