自定义的cell中如果存在着UIButton,那如何将点击事件传递出去呢?

自定义cell后,将indexPath参数传递到自定义的cell中(NSIndexPath为cell的一个retain的属性),自定义的cell申明一个协议,里面提供了一个方法

- (void)touchEventAtIndexPath:(NSIndexPath *)indexPath;

......

@property (nonatomic, assign) id<AppTableViewCellDelegate>delegate; // 将事件传递出去

......

- (void)buttonsEvent:(UIButton *)button
{
    // 将点击事件传递出去
    [self.delegate touchEventAtIndexPath:_indexPath];
}

当然,也可以用block实现。利用block传递indexPath。

原文地址:https://www.cnblogs.com/Crazy-ZY/p/5403914.html