iOS:使用Block回调按钮事件(自定义view)
2015-03-30 21:24
316 查看
自定义CustomView,在头文件中提供block回调函数
给其中的UIButton绑定事件监听器
自定义View监听到按钮点击事件后,调用回调函数
CustomSuperView中添加CustomView,并公开customViewButtonClickBlcok方法
在其内部实现以下内容:
最终控制器调用回调函数
实现:控制器->自定义View->自定义View中Button的事件通过Block的调用
@property (nonatomic, copy) void(^buttonClickBlcok)(NSInteger index);
给其中的UIButton绑定事件监听器
[button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
自定义View监听到按钮点击事件后,调用回调函数
- (void)buttonClick:(UIButton *)button { if (self.buttonClickBlcok) { self.buttonClickBlcok(button.tag); } }
CustomSuperView中添加CustomView,并公开customViewButtonClickBlcok方法
@property (nonatomic, strong) void(^customViewButtonClickBlcok)(NSInteger index);
在其内部实现以下内容:
@property (nonatomic, strong) CustomView *customView;
__weak CustomSuperView *weakSelf = self; [_customView setButtonClickBlcok:^(NSInteger index) { if (weakSelf.customViewButtonClickBlcok) { weakSelf.customViewButtonClickBlcok(index); } }];
最终控制器调用回调函数
@property (nonatomic, strong) CustomSuperView *customSuperView;
[customSuperView setCustomViewButtonClickBlcok:^(NSInteger index) { //TODO... NSLog(@"-------%zd",index); }];
实现:控制器->自定义View->自定义View中Button的事件通过Block的调用
相关文章推荐
- IOS学习——自定义View与使用block实现事件处理入门
- IOS自定义View使用block实现点击事件
- Android中使用回调接口实现自定义view的点击事件
- Android中Recyclerview使用7----条目中按钮点击事件,在activity中调用(接口回调)
- iOS:使用block代码块实现事件处理过程中的回调
- 接口的使用—自定义view点击事件的接口回调
- ios tableView 自定义cell上的按钮点击事件不好用
- IOS UIControl使用block作为事件捕获回调
- 基于Android中Webview使用自定义的javascript进行回调的问题详解
- 【IOS】自定义UIAlertView样式,实现可替换背景和按钮
- [ios] 自定义UIAlertView样式,实现可替换背景和按钮 【转】
- Android中Webview使用自定义的javascript进行回调
- IOS 使用自定义手势屏蔽按钮解决方法/UITapGestureRecognizer屏蔽Button
- Ios使用按钮自定义segmentcontrol
- IOS 使用block完成网络请求的自定义类BlockURLConnection
- IOS 构造和使用TableView(基于storyboard) (二)接收和处理Table View事件
- 【IOS】自定义UIAlertView样式,实现可替换背景和按钮
- IOS 使用XIB 自定义View
- iOS界面不能点击(tableView 的cell 不能使用点击事件,tableView也不能上下滚动)
- AlertDialog中使用自定义View,其中的Button如何设置点击事件监听