iphone - How to use NSInvocation to call a class method? -
i've class method not declared in h file, implemented in m file. want call in class, since return value int, can't use selector directly, use nsinvocation.
below i'm doing:
sel selector = ***; nsmethodsignature *signature = [classa methodsignatureforselector:selector]; nsinvocation *invocation = [nsinvocation invocationwithmethodsignature:signature]; invocation.selector = selector; invocation.target = [classa class]; [invocation setargument:(void *)arg atindex:2]; [invocation invoke];
the invoke doesn't succeed, why?
when passing arguments, pass address, not value. try following:
[invocation setargument:&arg atindex:2];
see [nsinvocation setargument:atindex:]
in class reference.
Comments
Post a Comment