美文网首页
iOS 利用runtime找到点击的页面

iOS 利用runtime找到点击的页面

作者: 阳光下的我眯起了眼睛 | 来源:发表于2018-07-04 22:42 被阅读22次

利用runtime实现的一个小功能。进入一个新页面,迅速找到对应的ViewController。

#import "UIViewController+Swizzling.h"
#import <objc/runtime.h>

@implementation UIViewController (Swizzling)

+(void)load{
#ifdef DEBUG
    Method viewWillAppear = class_getInstanceMethod(self, @selector(viewWillAppear:));
    Method logViewWillAppear = class_getInstanceMethod(self, @selector(loadViewWillAppear:));
    method_exchangeImplementations(viewWillAppear, logViewWillAppear);
#endif
}

- (void)loadViewWillAppear:(BOOL)animated{
    [self loadViewWillAppear:animated];

    NSString* className = NSStringFromClass([self class]);
    NSLog(@"我的名字是:%@",className);
}


@end

相关文章

网友评论

      本文标题:iOS 利用runtime找到点击的页面

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