Display button on UICollectionViewCell after UILongPressGestureRecognizer

263 views Asked by At

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

1

There are 1 answers

0
Kelvin Lau On BEST ANSWER

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 modifies cell.exitButton.hidden = true to cell.exitButton.hidden = exitButtonHidden.

Now, you need to do is call reloadData on the collectionView whenever you detect the long press so that the collectionView gets a chance to refresh all the cells again.