【发布时间】:2018-05-21 11:39:53
【问题描述】:
我正在尝试更改集合视图中选定自定义视图的颜色。我正在使用相同的集合视图的 didSelectItem 和 didDeselectItem 方法。
当我要更改 collectionview 中的不可见单元格时,我遇到了错误。
集合视图的可见单元格工作正常
我的代码在下面
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let cell = colCellSize.cellForItem(at: indexPath) as! colSizeDetails
cell.viewDetails.backgroundColor = UIColor.gray
cell.lblSize.textColor = UIColor.white
}
func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
let cell = colCellSize.cellForItem(at: indexPath) as! colSizeDetails
cell.viewDetails.layer.borderWidth = 2.0
cell.viewDetails.layer.borderColor = UIColor.gray.cgColor
cell.lblSize.textColor = UIColor.gray
cell.viewDetails.backgroundColor = UIColor.white
}
【问题讨论】:
-
错误说明了什么?请发布错误日志
-
线程 1:致命错误:在展开可选值时意外发现 nil -- 不显示错误日志。获取零索引路径
-
该错误表明您正在解开一个初始值为 nil 的可选值。您没有提供初始化不可见单元格的位置以及取消它的时间。请提供更多代码sn-ps。
标签: ios swift uicollectionview uicollectionviewcell