JCAssistant 0.0.3

JCAssistant 0.0.3

测试已测试
Lang语言 Obj-CObjective C
许可 MIT
发布上次发布2017年4月

wangyp2018维护。



  • 作者
  • wangyp2018

为 iOS 开发提供方便的一些小工具的集合

感兴趣的可以加QQ群交流:70835656 (JC开源项目交流)

安装

手动安装(一)

  1. 下载 JCAssistant 项目
  2. 将 JCAssistant 文件夹拖入到项目中
  3. 引用头文件 #import "JCAssistant.h"

手动安装(二)

  1. 下载 JCAssistant 项目
  2. 将相关文件拖入到项目中

目录

UI控件

KVO

UI控件

UIControl+JC_Extension

addTarget

在 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(@"我被点击了");
}];

removeTarget

使用 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];

KVO