我有一個UICollectionView,用戶可以選擇多個單元格。跟蹤哪些單元格已被選中是有點困難的,所以當單元格被點擊時,我需要一些方法來突出顯示/創建邊框。如何突出顯示選定的UICollectionView單元格? (Swift)
代碼:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell: CardsCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! CardsCollectionViewCell
parseObjects[indexPath.row].getDataInBackgroundWithBlock{
(imageData: NSData?, error: NSError?) -> Void in
if error == nil {
let image = UIImage(data: imageData!)
cell.cardsImg.image = image
}
}
//cell.cardLabel.text = imageNames[indexPath.row]
return cell
}
func collectionView(collectionView: UICollectionView, shouldSelectItemAtIndexPath indexPath: NSIndexPath) -> Bool {
addToList.append(objectsArray[indexPath.row])
return true
}
只使用didselect和diddeselect委託方法:) – longbow