Ich möchte die IsEditable-Eigenschaft in meinem HomeCollectionViewCell-Controller ändern, wenn ich meine HomeCollectionView lange drücke. Ich kann sie jedoch nur in der cellForItemAtIndexPath-Methode festlegen. Ich möchte sie in handleLongPress Methode setzen.Wie ändere ich die Eigenschaft in meiner UICollectionViewCell?
hier ist mein Eigentum in HomeCollectionViewCell
var isEditable:Bool = false {
didSet {
updateUI()
}
}
func updateUI(){
videoImage.image! = videoInformation.featuredImage
videoImage.contentMode = .ScaleAspectFill
videoTitle.text! = videoInformation.title
if isEditable {
deleteButton.hidden = false
} else {
deleteButton.hidden = true
}
}
hier meine handleLongPress Methode ist:
func editVideoFiles(sender: UILongPressGestureRecognizer) {
if sender.state == UIGestureRecognizerState.Began{
let p:CGPoint = sender.locationInView(self.collectionView)
let index: NSIndexPath = self.collectionView.indexPathForItemAtPoint(p)!
if let cell = self.collectionView.cellForItemAtIndexPath(index) {
//cell is the UICollectionViewCell, I do not know how to set the isEditable property by this.
}
}
}
Danke! Aber ich möchte die Eigenschaft all meiner sichtbaren Zellen festlegen. Wenn ich für cell in collectionView.visibleCells() verwende, kann ich cell nicht in HomeCollectionViewCell umwandeln. Kannst du mir sagen, wie ich das machen soll? – leuction
Ich habe dieses Problem gelöst, sagen Sie einfach für Zelle in (self.collectionView.visibleCells() als? [HomeCollectionViewCell])! – leuction