2016-08-12 33 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 
     } 
    } 
} 
相關問題