Is it possible to call a static method using '@selector'?
I've tried using the code below (which is part of an action Sequence) but the compiler complains...
[CallFunc actionWithTarget:self selector:@selector([MyClass myStaticMethod)]
A fast, easy to use, free, and community supported 2D game engine
Is it possible to call a static method using '@selector'?
I've tried using the code below (which is part of an action Sequence) but the compiler complains...
[CallFunc actionWithTarget:self selector:@selector([MyClass myStaticMethod)]
did you try with selector:@selector(@"nameOfStaticMethod")? Assuming its a static method of the class as self.
Hi Codemattic,
I tried your suggestion but unfortunately it doesn't work, although the compiler doesn't complain you do get a crash at runtime, see the error below:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[Introduction navigateToMainMenu]: unrecognized selector sent to instance 0x4060210'
Any other ideas?
A static method is nothing but an instance method on the class object. Every class you make (such as MyClass) is actually an object and you can call methods on it (that's what happens with [MyClass alloc], for example).
Try this:
[CallFunc actionWithTarget:[self class] selector:@selector(myStaticMethod)]
That worked brilliantly, thanks Poltras!
I am having the same problem when invoking a static method in a global class. There is no compiler warning, but app crashes at +[NSInvocation invocationWithMethodSignature].
The call:
id showHelpAction = [CCCallFuncND actionWithTarget:[MyGlobals class] selector:@selector(foo:data:) data:@"fight"];
The global class:
@interface MyGlobals : NSObject {
}
+(void)foo:(id)node data:(void *)s;
@endi'm just guessing, but shouldn't your method declaration read like this if you're passing it an NSString (@"fight") ?
@interface MyGlobals : NSObject {
}
+(void)foo:(id)node data:(NSString *)s;
@endTried that and it choked too.
Note: If the method was in self, it works just fine via CCCallFunc.
You must log in to post.