萤石云 iOSSDK,移植跨平台相关工程
Davin
2024-12-18 b4e1288a9b63eb820e9c9489c56aac4bf6b31067
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//
//  HDLEZDetectionTypeView.m
//  EZSDK
//
//  Created by Davin on 2023/8/5.
//
 
#import "HDLEZDetectionTypeView.h"
#import "HDLEZDetectionTypeCell.h"
 
@interface HDLEZDetectionTypeView ()<UITableViewDataSource, UITableViewDelegate> {
    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<HDLEZDetectionTypeModel *> *)detectionTypeList {
    _detectionTypeList = detectionTypeList;
    
    [self reloadData];
}
 
@end