例如一個(gè)cell上的點(diǎn)擊事件,通過(guò)block回調(diào)給控制器處理
cell頭文件:
#import <UIKit/UIKit.h>
typedef void(^checkMessage)(NSInteger index);
@interface InformationCell : UITableViewCell
@property(nonatomic,copy) checkMessage clickBack;
@end
cell實(shí)現(xiàn)文件
#pragma mark - 點(diǎn)擊事件
- (void)clickMessage:(UIButton *)button {
NSInteger index = button.tag;
self.clickBack(index);
}
block回調(diào)給控制器處理
- (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;
}