我有集合视图具有两个海关细胞,我有一个方法,该方法选择的细胞的边界出现在选定的一些情况下,并且取消所有选择的按钮,问题是当按下按钮时,单元格边框被设置为清除颜色,但是当再次进入选择模式时,先前选择的单元格仍然有边框,所以我要找的是当我取消选择然后再次进入选择模式时,没有单元格应该是这里是代码: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 {
}
}
仍然在其工作时取消,谢谢:) –