test *Test = [[test alloc]init];
// //方式一
// void(*setSkinColor_Func) (id, SEL, NSString*);
// setSkinColor_Func=(void (*)(id, SEL, NSString*)) [Test methodForSelector:NSSelectorFromString(@"test:")];
// setSkinColor_Func(Test,NSSelectorFromString(@"test:"),@"verbose");
//方式二 该方式只限于在非ARC下使用,否则在运行时回中断
// IMP imp = [Test methodForSelector:@selector(test2:)];
// imp(Test,@selector(test:),@"asf");
//方式三
IMP imp = [Test methodForSelector:@selector(test:)];
void (*func)(__strong id,SEL,...) = (void (*)(__strong id, SEL, ...))imp;
func( Test, @selector(test:),@"afjsdl");IMP 使用
最新推荐文章于 2025-07-29 09:10:01 发布
本文介绍了一种在 Objective-C 中利用运行时特性动态调用方法的方式,展示了三种不同的方法调用手段,并重点讲解了如何通过 IMP 和 C 函数指针的方式进行方法调用。

380

被折叠的 条评论
为什么被折叠?



