CNLiveVodAlbumListCell.swift
3.75 KB
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
//
// CNLiveVodAlbumListCell.swift
// metaCode
//
// Created by zx on 2025/3/4.
//
import Foundation
typealias CNLiveVodAlbumListCellSelectBlock = (_ vodModel:CNLiveVodAlbumListModel,_ index:Int,_ albumListModels:NSMutableArray,_ vodAlbumListBaseModel:CNLiveVodAlbumListBaseModel?)->Void;
class CNLiveVodAlbumListCell:UITableViewCell, UICollectionViewDelegate, UICollectionViewDataSource{
var currSeleIdx:Int = 0
var selectBlock:CNLiveVodAlbumListCellSelectBlock?
//实时热榜的列表
lazy var albumListArr: NSMutableArray = {
var albumListArr = NSMutableArray()
return albumListArr
}()
let kCNLiveVodAlbumListCollectionCellIdentifier = "kCNLiveVodAlbumListCollectionCellIdentifier"
lazy var realHotCollectionView: UICollectionView = {
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .horizontal
layout.itemSize = CGSizeMake(50, 50)
layout.sectionInset = .init(top: 0, left: 0, bottom: 0, right: 0)
layout.minimumLineSpacing = 5
let cv = UICollectionView(frame: .zero, collectionViewLayout: layout)
cv.delegate = self
cv.dataSource = self
cv.backgroundColor = .white
cv.showsHorizontalScrollIndicator = false
cv.register(CNLiveVodAlbumListCollectionCell.self, forCellWithReuseIdentifier: kCNLiveVodAlbumListCollectionCellIdentifier)
return cv
}()
//
var _vodAlbumListBaseModel : CNLiveVodAlbumListBaseModel?
var vodAlbumListBaseModel : CNLiveVodAlbumListBaseModel? {
get{
_vodAlbumListBaseModel
}
set{
_vodAlbumListBaseModel = newValue!
self.setupNewUI(model: vodAlbumListBaseModel!)
}
}
//MARK: - 懒加载
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.selectionStyle = .none
setupUI()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func setupUI() {
contentView.backgroundColor = .white
self.contentView.addSubview(self.realHotCollectionView)
self.realHotCollectionView.frame = CGRect(x: 10, y: 0, width: KSreenWidth-20, height: 51)
}
func setupNewUI(model:CNLiveVodAlbumListBaseModel){
self.albumListArr = NSMutableArray(array: model.list)
self.realHotCollectionView.reloadData()
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
self.albumListArr.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: kCNLiveVodAlbumListCollectionCellIdentifier, for: indexPath) as! CNLiveVodAlbumListCollectionCell
if self.currSeleIdx == indexPath.row{
//当前cell选中
cell.isJiShuSelected = true
}else{
//不选中
cell.isJiShuSelected = false
}
cell.num = indexPath.row
cell.vodAlbumListModel = self.albumListArr[indexPath.row] as? CNLiveVodAlbumListModel
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if let vodAlbumListModel = self.albumListArr[indexPath.row] as? CNLiveVodAlbumListModel{
//点击某集,刷新页面
self.selectBlock?(vodAlbumListModel, indexPath.row, self.albumListArr, self.vodAlbumListBaseModel)
self.currSeleIdx = indexPath.row
self.realHotCollectionView.reloadData()
}
}
}