block简单回调

例如一个cell上的点击事件,通过block回调给控制器处理

cell头文件:

#import <UIKit/UIKit.h>

typedef void(^checkMessage)(NSInteger index);

@interface InformationCell : UITableViewCell

@property(nonatomic,copy) checkMessage clickBack;

@end

cell实现文件

#pragma mark - 点击事件
- (void)clickMessage:(UIButton *)button {
    NSInteger index = button.tag;
    self.clickBack(index);
}

block回调给控制器处理

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    __weak typeof(self) weakSelf = self;
    static NSString *cellId = @"informationCell";
    InformationCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (!cell) {
        cell = [[InformationCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
    }
    NewsLastModel *model = _lastNewsDataSource[indexPath.row];
    cell.model = model;
    cell.clickBack = ^(NSInteger index) {
        __strong typeof(weakSelf) strongSelf = weakSelf;
        [strongSelf checkMessageWithIndex:index model:model];
    };
    return cell;
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • iOS网络架构讨论梳理整理中。。。 其实如果没有APIManager这一层是没法使用delegate的,毕竟多个单...
    yhtang阅读 10,708评论 1 23
  • 2017.02.22 可以练习,每当这个时候,脑袋就犯困,我这脑袋真是神奇呀,一说让你做事情,你就犯困,你可不要太...
    Carden阅读 5,259评论 0 1
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 14,763评论 4 61
  • 练习flex相关属性用法可以在浏览器开发者工具上练习 可以设置在容器(.boxes)上的属性 可以设置在容器(.b...
    谨言_慎行阅读 2,629评论 0 0
  • 崩溃之后的我,还是回到了珠海 大巴,窗前,大海……我知道我回到了珠海,那个令我无比尴尬的地界无心,又是静静的看着,...
    辉狼_fish阅读 1,823评论 1 0

友情链接更多精彩内容