iOS 利用runtime找到点击的页面

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

#import "UIViewController+Swizzling.h"
#import 

@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找到点击的页面)