【发布时间】:2021-01-08 19:15:55
【问题描述】:
我有一个(水平的)collectionView,它位于 tableViewCell 中。
我的 tableViewCell 行有一个 label 和 collectionView
Collectionview 在每个单元格中都有按钮
当点击按钮时,我会突出显示按钮的颜色和 tableCell 的行,这是完美的工作。我对 prepareForReuse() 有疑问
场景:我点击了按钮,它改变了它的颜色(在 collectionCell 中)并突出显示 tableViewCell 的行和 我有 10 多个表行。 当我向下滚动 tableView 时,我看到我在 tableRow1 上所做的选择出现在 tableRow10 中
我在 tableviewcell 中添加了 prepareForReuse(),但是如何从 table 的 prepareForReuse() 引用和重置 collectionview 内的按钮外观
请指教
// This is my tableCell reuse method
override func prepareForReuse() {
super.prepareForReuse()
tableCellLabel.text = nil
// Reset collectionViewCell button display here
}
// This is my collectionView Datasource method:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ActivitySlotCollectionViewCell.identifier, for: indexPath) as! ActivitySlotCollectionViewCell
cell.configure(from: dataModel)
return cell
}
// This is my collectionViewCell reuseMethod
override func prepareForReuse() {
super.prepareForReuse()
isButtonSelected = false
slotButton.setTitleColor(UIColor.blue, for: .normal)
slotButton.layer.borderColor = isButtonSelected ? UIColor.white.cgColor : UIColor.black.cgColor
slotButton.backgroundColor = isButtonSelected ? UIColor.red : UIColor.clear
}
【问题讨论】:
标签: ios uitableview uicollectionview uicollectionviewcell prepareforreuse