TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Apr 2017 |
Maintained by wangyp2018.
为iOS开发提供方便的一些小工具的集合
感兴趣的可以加QQ群交流:70835656 (JC开源项目交流)
#import "JCAssistant.h"
对UIControl添加监控事件,如给UIButton添加点击事件,我们会这样写:
//添加UIControlEventTouchUpInside事件
[button addTarget:self action:@selector(buttonAction:) forControlEvents: UIControlEventTouchUpInside];
//事件处理方法
- (void)buttonAction:(UIButton*)sender{
//TO-DO
}
使用JCAssistant就可以这样写:
#import <JCAssistant/JCAssistant.h>
或
#import <JCAssistant/UIControl+JC_Extension.h>
[button jc_actionWithEvent:UIControlEventTouchUpInside usingBlock:^{
NSLog(@"我被点击了");
}];
使用JCAssistant为UIControl添加的事件监听可以通过jc_removeActionWithEvent/jc_removeAllAction
对其进行移除监听
//移除UIControlEventTouchUpInside
[button jc_removeActionWithEvent:UIControlEventTouchUpInside];
//移除所有监听
[button jc_removeAllAction];
如果用JCAssistant添加了多个监听事件,如:
[button jc_actionWithEvent:UIControlEventTouchUpInside usingBlock:^{
NSLog(@"---执行--1--");
}];
[button jc_actionWithEvent:UIControlEventTouchUpOutside usingBlock:^{
NSLog(@"---执行--2--");
}];
可以这样移除:
//分多次移除
[button jc_removeActionWithEvent:UIControlEventTouchUpInside];
[button jc_removeActionWithEvent:UIControlEventTouchUpOutside];
//一次性移除
[button jc_removeActionWithEvent:UIControlEventTouchUpOutside | UIControlEventTouchUpInside];