如何在 didSelectItemAtIndexPath 处设置 Collection View 中任何单元格的值。所以我想将所有其他单元格的边框颜色更改为黑色,除了用户单击的单元格。
谢谢
最佳答案
您可以通过保留选择和索引的引用来实现这一点
var isSelected:Bool = false;
var index: Int;
并在 didSelectItemAtIndexPath 中将 isselected 属性更改为 true 并将索引路径行值保留在索引中,然后重新加载 Collection View
当您填充单元格时添加条件
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
if(isSelected && indexPath.Row != index )
{
// change the color to the black
}
}
关于ios - 如何通过 UICollectionViewController (Swift) 中的 didSelectItemAtIndexPath() 方法访问所有单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38925159/