2016-08-12 53 views

回答

0

您可以通过保持选择和指标的参考实现这一

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 
    } 

} 
0

下面的代码遍历的实现代码如下部分,每个部分的行。它将每行的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 
     } 
    } 
} 
相关问题