// according to x value we will have m1, m2 or m3 as string.
NSString * methodName = [NSString stringWithFormat:@"m%@", x ];
SEL myMethod = @selector(methodName);
// then what?
NSTimer *myTimer = [[NSTimer scheduledTimerWithTimeInterval:0.5
target:self selector:myMethod
userInfo:nil repeats:NO] retain];
[myTimer release];
???? this do not seems to work.
I am receiving an error message telling me that methodName variable is not being used...
// according to x value we will have m1, m2 or m3 as string.
NSString * methodName = [NSString stringWithFormat:@"m%@", x ];
SEL myMethod = @selector(methodName);
// then what?
NSTimer *myTimer = [[NSTimer scheduledTimerWithTimeInterval:0.5
target:self selector:myMethod
userInfo:nil repeats:NO] retain];
[myTimer release];
???? this do not seems to work.
I am receiving an error message telling me that methodName variable is not being used...
I suspect that the "@selector(methodName)" in your code isn't doing what you think it's doing.
My understanding of the @selector(some_name_here) construct is that it's an Objective-C directive that instructs the compiler to build a selector with the named parameter. So "@selector(methodName)" builds a selector with the name "methodName", and that's it. The "methodName" used to build the selector has no association with the "methodName" variable you have declared in your code.
Is the "x" that you're using to determine your callback a persistent variable? If so, there is a perhaps a simple solution to this problem. Can you see it?
Sorry, you misunderstood my post. What you can't do is pass a variable to the @selector directive. Of course you can assign the result of @selector to a SEL variable. The part in the parentheses can't be a variable.
Lunar was originally trying to set the selector using an NSString. What you are doing is right, but if you want to set the selector based off of a string like Lunar originally attempted, Ricks solution is correct.