iOS runtime实用篇
来源:互联网 发布:linux渗透有什么用 编辑:程序博客网 时间:2024/05/17 01:10
通常对于一个新接手的项目,我们会想知道哪页对应的是哪个VC,如果想实现点到页面就打印对应的类,会有以下两个方法。
方案1
- 适用新项目 (基类)
整个项目中建立一个基类的viewController,然后将项目中所有的viewController都继承于基类的viewController,然后重写基类中的viewWillAppear方法
- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; NSString *className = NSStringFromClass([self class]); NSLog(@"%@ will appear", className);}
方案2
- 不论是从零开始搭建的项目,还是已经成型的项目,都适用。(runtime方法交换)
//// UIViewController+Swizzling.m// RunTimeDemo//// Created by LXChen on 2017/5/17.// Copyright © 2017年 LXChen. All rights reserved.//#import "UIViewController+Swizzling.h"#import @implementation UIViewController (Swizzling)+ (void)load { //我们只有在开发的时候才需要查看哪个viewController将出现 //所以在release模式下就没必要进行方法的交换#ifdef DEBUG //原本的viewWillAppear方法 Method viewWillAppear = class_getInstanceMethod(self, @selector(viewWillAppear:)); //需要替换成 能够输出日志的viewWillAppear Method logViewWillAppear = class_getInstanceMethod(self, @selector(logViewWillAppear:)); //两方法进行交换 method_exchangeImplementations(viewWillAppear, logViewWillAppear);#endif}- (void)logViewWillAppear:(BOOL)animated { NSString *className = NSStringFromClass([self class]); //在这里,你可以进行过滤操作,指定哪些viewController需要打印,哪些不需要打印 if ([className hasPrefix:@"UI"] == NO) { NSLog(@"%@ will appear",className); } //下面方法的调用,其实是调用viewWillAppear [self logViewWillAppear:animated];}@end
阅读全文
0 0
- iOS runtime实用篇
- iOS runtime实用篇
- iOS runtime实用篇 ---避免常见崩溃
- iOS 万能跳转界面方法(runtime实用篇一)
- iOS 万能跳转界面方法 (runtime实用篇一)
- iOS 万能跳转界面方法 (runtime实用篇一)
- iOS 万能跳转界面方法 (runtime实用篇一)
- iOS 万能跳转界面方法 (runtime实用篇一)
- iOS 万能跳转界面方法 (runtime实用篇一)
- iOS 万能跳转界面方法 (runtime实用篇一)
- iOS 万能跳转界面方法 (runtime实用篇一)
- iOS 万能跳转界面方法(runtime实用篇一)
- iOS 万能跳转界面方法 (runtime实用篇一)
- iOS 万能跳转界面方法 (runtime实用篇一)
- iOS 万能跳转界面方法 (runtime实用篇一)
- iOS 万能跳转界面方法 (runtime实用篇一)
- iOS 万能跳转界面方法 (runtime实用篇一)
- iOS 万能跳转界面方法 (runtime实用篇一)
- 回声问题和回声消除技术及在可视监控对讲、楼宇对讲等领域的应用综述
- 域控制器的常规卸载,Active Directory系列之十三
- Android加载中动画AVLoadingIndicatorView的使用封装
- java基础之自定义队列实现
- HDU4027
- iOS runtime实用篇
- 如何将自己写的项目上传到github上?
- java自定义异常
- 路由生产算法
- java堆与栈的理解
- spring注入的processEngine突然就不好使了,项目启动不了
- qt对话框不在任务栏显示
- 视图
- 域控制器的强制卸载,Active Directory系列之十四