美文网首页
Runtime使用三 (查看界面在那个控制器)

Runtime使用三 (查看界面在那个控制器)

作者: e40c669177be | 来源:发表于2018-12-06 11:53 被阅读13次

第一次这么大规模的使用runtime , 原来只知道runtime, 但是感觉离我的生活好远, 偶尔使用还是改输入框的光标的颜色 😂😂. 这次时间紧, 任务重, 为了节省时间, 就打上了runtime的主意

没想到这么好用

果然人都是被逼出来的

#import "UIViewController+LoadVC.h"

#import <objc/runtime.h>

@implementation UIViewController (LoadVC)

+(void)load{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
    Method oldMethod = class_getInstanceMethod([self class], @selector(viewWillAppear:));
    Method newMethod = class_getInstanceMethod([self class], @selector(hook_ViewWillAppear:));
    method_exchangeImplementations(oldMethod, newMethod);
});
}



-(void)hook_ViewWillAppear:(BOOL)appear{
NSString *className = NSStringFromClass([self class]);
NSLog(@"%@ will appear", className);
[self hook_ViewWillAppear:appear];

  }
@end

相关文章

网友评论

      本文标题:Runtime使用三 (查看界面在那个控制器)

      本文链接:https://www.haomeiwen.com/subject/ongncqtx.html