// // HDLEZDetectionTypeView.m // EZSDK // // Created by Davin on 2023/8/5. // #import "HDLEZDetectionTypeView.h" #import "HDLEZDetectionTypeCell.h" @interface HDLEZDetectionTypeView () { CGFloat cellHeight; } @property (nonatomic, copy) void(^selectedDetectionType)(NSString *code); @end @implementation HDLEZDetectionTypeView -(instancetype)init{ self = [super init]; if (self) { self.backgroundColor = HDLEZ_COLOR_VIEW_BACKGROUND; self.separatorStyle = NO; self.showsVerticalScrollIndicator=NO; self.delegate = self; self.dataSource = self; cellHeight=60; self.rowHeight = UITableViewAutomaticDimension; self.estimatedRowHeight = 60; [self registerClass:[HDLEZDetectionTypeCell class] forCellReuseIdentifier:@"HDLEZDetectionTypeCell"]; [self setSeparatorInset:UIEdgeInsetsZero]; } return self; } -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.detectionTypeList.count; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return UITableViewAutomaticDimension; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ HDLEZLog(@"初始化cell"); HDLEZDetectionTypeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HDLEZDetectionTypeCell" forIndexPath:indexPath]; if(cell == nil){ cell=[[HDLEZDetectionTypeCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"HDLEZVideoDoorMsgCell"]; } cell.selectionStyle = UITableViewCellSelectionStyleNone; [self configCell:cell indexPath:indexPath]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (self.detectionTypeList.count <= indexPath.row) return; HDLEZDetectionTypeModel *typeModel = self.detectionTypeList[indexPath.row]; [self selelctedDetectionType:typeModel]; } #pragma mark - PublishMethod - (void)didSelectedDetectionType:(void(^)(NSString *code))selectedBlock { self.selectedDetectionType = selectedBlock; } #pragma mark - PrivateMethod - (void)configCell:(HDLEZDetectionTypeCell *)cell indexPath:(NSIndexPath *)indexPath { if (self.detectionTypeList.count <= indexPath.row) return; HDLEZDetectionTypeModel *typeModel = self.detectionTypeList[indexPath.row]; [cell configDetectionType:typeModel.desc selected:typeModel.status]; } - (void)selelctedDetectionType:(HDLEZDetectionTypeModel *)selectedModel { for (HDLEZDetectionTypeModel *model in self.detectionTypeList) { model.status = NO; } selectedModel.status = YES; [self reloadData]; if (self.selectedDetectionType) { self.selectedDetectionType(selectedModel.code); } } #pragma makr - Setter - (void)setDetectionTypeList:(NSArray *)detectionTypeList { _detectionTypeList = detectionTypeList; [self reloadData]; } @end