たとえば、sthの実装中に奇妙なコンパイルの問題があります
作品:
[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が初めてであることに注意してください)