例如,在一个静态库中,调用外面的类的方法
// param1 (类名) param2 (类中的方法)
NSString *param1 =@"YCAdBaiduBannerAdapter";
NSString *param2 =@"initWithAdKey:";
id class =[[NSClassFromString(param1)alloc]init];
if (class) {
SEL selector =NSSelectorFromString(param2);
if ([class respondsToSelector:selector]) {
NSInvocation *inv =[NSInvocation invocationWithMethodSignature:[class methodSignatureForSelector:selector]];
//方法中的参数 argument
NSString *argument =@"1232";
[inv setSelector:selector];
[inv setTarget:class];
[inv setArgument:&argument atIndex:2];
[inv invoke];
}
}