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