如何在我的集合视图的didSelectItemAtIndexPath中设置任何单元格的值。所以我想将所有其他单元格的边框颜色更改为黑色,以期望用户单击的单元格。如何访问UICollectionViewController(Swift)中的method didSelectItemAtIndexPath()的所有单元格
谢谢
如何在我的集合视图的didSelectItemAtIndexPath中设置任何单元格的值。所以我想将所有其他单元格的边框颜色更改为黑色,以期望用户单击的单元格。如何访问UICollectionViewController(Swift)中的method didSelectItemAtIndexPath()的所有单元格
谢谢
您可以通过保持选择和指标的参考实现这一
var isSelected:Bool = false;
var index: Int;
和didSelectItemAtIndexPath改变IsSelected属性为true,并保证指数路径行值索引然后重新集合视图
当您填充您的单元格时,添加条件
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
if(isSelected && indexPath.Row != index)
{
// change the color to the black
}
}
下面的代码遍历的实现代码如下部分,每个部分的行。它将每行的indexPath与所选单元格的indexPath进行比较,如果它们不匹配,则允许您对单元格执行所需的操作。
for (NSInteger i = 0; i < [tableView numberOfSections]; ++i)
{
for (NSInteger j = 0; j < [tableView numberOfRowsInSection:i]; ++j)
{
NSIndexPath *cellIdxPath = [NSIndexPath indexPathForRow:j inSection:i];
// indexPath represents the currently selected row
if (indexPath != cellIdxPath)
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:cellIdxPath];
// do whatever you need to do to the cell
}
}
}