我在实现某事时遇到了奇怪的编译问题,例如
作品:
[self performSelector:NSSelectorFromString(member)];
不工作:
SEL method=NSSelectorFromString(member);
[self performSelector:method];
编译器哭着:
methods.m:31: error: expected expression before ‘SEL’
methods.m:32: error: ‘method’ undeclared (first use in this function)
methods.m:32: error: (Each undeclared identifier is reported only once
methods.m:32: error: for each function it appears in.)
完整方法:
- (void)printArgs:(NSString *)member
{
//int val=[self compareIt:member];
switch ([self compareIt:member])
{
case 1:
//dynamically call method
SEL method;
method = NSSelectorFromString(member);
NSLog(@"\n%@ is a object Member , with value: %i\n", member, [self performSelector:method]);
break;
default:
NSLog(@"\nWrong option :%@ \n", member);
}
}
@end
请指出我正确的方向。(请注意我是 Objective-C 的新手)