I have a UILongPressGestureRecognizer on a Cell from a CollectionView and I want to display a button from that (and all the others) cells after a long touch happens. Here's my code:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell: CellController = collection.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! CellController
cell.exitButton.hidden = true
return cell
}
I want to set to false the cell.exitButton.hidden after the touch happen.
Thanks in advance
Have a bool variable in the collectionView's class scope. When you detect the long press, modify the bool variable. In this example, I'll declare it as
var exitButtonHidden = true.Change your implementation of
cellForItemAtIndexPath, such that it modifiescell.exitButton.hidden = truetocell.exitButton.hidden = exitButtonHidden.Now, you need to do is call
reloadDataon the collectionView whenever you detect the long press so that the collectionView gets a chance to refresh all the cells again.