ios - 如何通过 UICollectionViewController (Swift) 中的 didSelectItemAtIndexPath() 方法访问所有单元格

标签 ios swift uicollectionview

如何在 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/

相关文章:

ios - iOS 的 codename1.ext.codescan cn1lib 有问题

ios - 从不正确的线程访问的 Realm 。 iOS 最佳实践

swift - 继承符合协议(protocol)的类

swift - 无法使用 NSNib 加载 View

ios - UICollectionView | UICollectionView |电池可重复使用

ios - 按下 indexPath 单元格时如何导航或显示其他 View Controller

ios - 带有百分比符号的密码总是错误 iPhone

iOS 以编程方式将 AVI 转换为 MP4 格式

ios - NSUser Defaults - 将 3 个变量保存在一起然后获取

ios - 尽管宽度相等,但 Collection View 网格最后一行显示不同 - swift iOS