【发布时间】:2017-11-29 04:46:17
【问题描述】:
我使用 UIcollection 视图作为我的标签栏 当我水平滚动集合视图时,当我选择新单元格时,前一个选定的单元格不会取消选择
这是我选择一个单元格并取消选择一个单元格时更改颜色的代码
var selectedIndexPath : IndexPath = []
func collectionView(_ collectionView: UICollectionView,
didSelectItemAt indexPath: IndexPath) {
if let cell = collectionView.cellForItem(at: indexPath) as?
BottomCollectionViewCell {
cell.contentView.backgroundColor = UIColor.orange
cell.backgroundColor = UIColor.orange
}
if let preViousSelectedcell = collectionView.cellForItem(at:
selectedIndexPath) as? BottomCollectionViewCell {
preViousSelectedcell.contentView.backgroundColor=UIColor.purple
preViousSelectedcell.backgroundColor = UIColor.purple
}
selectedIndexPath = indexPath
}
【问题讨论】:
-
使用
collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) -
我已经使用了,但没有任何改变。我认为滚动视图时索引路径正在改变。
-
你能否更新你的答案,展示你是如何使用它的?
-
@Sath.Dev 如果您单击一个已被选中的单元格,则将调用取消选择,而不是如果您选择任何其他单元格。做一些研究,你会得到很多答案。
标签: ios uicollectionview swift4 xcode9