3
下面的代码按预期工作:如何从NSInvocation获取NSString结果?
NSLog(@"%@", [NSString stringWithString:@"test"]; // Logs "test"
但是,当我与NSInvocation
取代它,我得到一个完全不同的结果:
Class class = [NSString class];
SEL selector = @selector(stringWithString:);
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:
[class methodSignatureForSelector:selector]];
[invocation setTarget:class];
[invocation setSelector:selector];
[invocation setArgument:@"test" atIndex:2];
[invocation invoke];
id returnValue = nil;
[invocation getReturnValue:&returnValue];
NSLog(@"%@", returnValue); // Logs "NSCFString"
我已经搜查高有低,但找不出这一点。任何帮助?谢谢!
谢谢,谢谢,谢谢!我完全看错了。很长一段时间。 – 2011-03-07 19:47:39