Runtime_实现计算一个Button被点击次数
2016-02-08 22:02
190 查看
写一个分类 替换点击方法
#import "UIControl+Button.h"
#import <objc/objc-runtime.h>
@implementation UIControl (Button)
static int i =
0;
+ (void)load {
//runtime
进行方法替换
Method method =
class_getInstanceMethod([self
class], @selector(sendAction:to:forEvent:));
//create
方法
Method method2 =
class_getInstanceMethod([self
class], @selector(clickTimes));
method_exchangeImplementations(method, method2);
}
- (void)clickTimes {
i++;
NSLog(@"%d",i);
}
#import "UIControl+Button.h"
#import <objc/objc-runtime.h>
@implementation UIControl (Button)
static int i =
0;
+ (void)load {
//runtime
进行方法替换
Method method =
class_getInstanceMethod([self
class], @selector(sendAction:to:forEvent:));
//create
方法
Method method2 =
class_getInstanceMethod([self
class], @selector(clickTimes));
method_exchangeImplementations(method, method2);
}
- (void)clickTimes {
i++;
NSLog(@"%d",i);
}
相关文章推荐
- Java Runtime Environment 5.0 Update 12 下载
- php set_magic_quotes_runtime() 函数过时解决方法
- Asp.Net 程序错误Runtime Error原因与解决
- System 类 和 Runtime 类的常用用法介绍
- NET Runtime Optimization Service 1101 错误的解决方法
- 自动释放池的前世今生 ---- 深入解析 autoreleasepool
- 深入解析 ObjC 中方法的结构
- 你真的了解 load 方法么?
- 从源代码看 ObjC 中消息的发送
- IOS高级教程2:反射根据变量的引用获取变量名
- iOS runtime原理
- runtime 运行时机制 完全解读
- runtime实际应用
- Objective-C 的动态提示和技巧
- Objective-C Associated Objects 的实现原理
- (1)知识准备【利用objective-c的runtime特性,结合FMDB实现一个轻量级的ORM】
- (2)预期+思考【利用objective-c的runtime特性,结合FMDB实现轻量级的ORM】
- (3)实体和结构【利用objective-c的runtime特性,结合FMDB实现轻量级的ORM】
- (4)代码及测试【利用objective-c的runtime特性,结合FMDB实现轻量级的ORM】
- OC-RunTime-Method Swizzling