查询一个按钮是否绑定了某方法,开销会不会很大?

五虎将 2017-11-30 03:40:56
现在我试了一下查询方法的,检查按钮是否跟一个方法绑定了起来,发现查不到,只能查一个UIViewController动态添加的方法。代码在下面,有什么问题吗?

unsigned long imp_address = 0;
SEL buttonBackFunc_selector = @selector(clickBackButtonToHigerLevel:);
if([ViewControllertest checkExistenceOfAMethdInGivenClass:buttonBack selector:buttonBackFunc_selector imp_address:&imp_address]){
DBGLOG(@"clickBackButtonToHigerLevel");
}

+(BOOL) checkExistenceOfAMethdInGivenClass:(id)inspectObj selector:(SEL)ASelector imp_address:(unsigned long *)imp_address
{
unsigned long returnAddress = (unsigned long)__builtin_return_address(0);
Class class_self = object_getClass(inspectObj);
uint method_count;
Method *methodList = class_copyMethodList(class_self, &method_count);
NSString *self_name = [inspectObj class];
for(int i = 0;i < method_count;i++)
{
Method method = methodList[ i ];
SEL sel_method = method_getName(method);
if(!sel_isEqual(ASelector, sel_method)){
continue;//Ignore methods with different selectors
}
NSString *sn = NSStringFromSelector(sel_method);
IMP implement = method_getImplementation(method);
unsigned long address = (unsigned long)implement;
DBGLOG(@"%@,method_name%d:%@,address=:%lu",self_name,i,sn,address);
if(address > returnAddress)
{
*imp_address = address;
free(methodList);methodList = NULL;
return YES;
}
}
free(methodList);methodList = NULL;
*imp_address = NULL;
return NO;
}
...全文
302 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

29,027

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧