我有集合視圖具有兩個海關細胞,我有一個方法,該方法選擇的細胞的邊界出現在選定的一些情況下,並且取消所有選擇的按鈕,問題是當按下按鈕時,單元格邊框被設置爲清除顏色,但是當再次進入選擇模式時,先前選擇的單元格仍然有邊框,所以我要找的是當我取消選擇然後再次進入選擇模式時,沒有單元格應該是這裏是代碼:UIcollection查看多個選擇取消細胞
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
if isGridSelected {
let cell:cell2_Class = collectionView.dequeueReusableCellWithReuseIdentifier("cell2", forIndexPath: indexPath) as! cell2_Class
collectionView.allowsMultipleSelection = true
collectionView.allowsSelection = true
cell.listImage.image = imageArray[indexPath.row]
if self.selectedIndexes.indexOf(indexPath) == nil || cancel == true {
cell.layer.borderColor = UIColor.clearColor().CGColor
// Unselected
}
else if cancel == true { cell.layer.borderColor = UIColor.clearColor().CGColor
for indexPath: NSIndexPath in selectedIndexes {
self.collectionView.deselectItemAtIndexPath(indexPath, animated: false)
collectionView.reloadData()
}
} else {
cell.layer.borderColor = UIColor.greenColor().CGColor // Selected
cell.layer.borderWidth = 3
}
return cell
}
}
var flag = false
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
if flag == false{ self.performSegueWithIdentifier("showimage", sender: self) }
else if cancel == true {
let cell = collectionView.cellForItemAtIndexPath(indexPath)
cell?.selected = false
// deselect
} else if flag == true {
if let indexSelection = selectedIndexes.indexOf(indexPath) {
selectedIndexes.removeAtIndex(indexSelection)
} else {
selectedIndexes.append(indexPath)
}
self.collectionView.reloadData()
}
}
func handleLongPress(gestureReconizer: UILongPressGestureRecognizer) {
if gestureReconizer.state != UIGestureRecognizerState.Began {
return
}
let p = gestureReconizer.locationInView(self.collectionView)
let indexPath = self.collectionView.indexPathForItemAtPoint(p)
if indexPath != nil {
if let indexSelection = selectedIndexes.indexOf(indexPath!) {
selectedIndexes.removeAtIndex(indexSelection)
} else {
selectedIndexes.append(indexPath!)
}
print(indexPath?.row)
cancel = false
flag = true
self.title = "share photos"
cancelButton.hidden = false
} else {
}
}
仍然在其工作時取消,謝謝:) –