Reputation: 5599
I want to be able to edit records that are displayed in a collection view.
I've added an "Edit" button to the collection view. What is the best way to determine which cell is to be edited?
I thought of doing something like so:
func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
visibleCell = collectionView.visibleCells().first as MessageCell
}
I didn't want to add the edit button to the xib itself as I don't want the button to scroll when the cell scrolls
Upvotes: 1
Views: 423
Reputation: 908
One possibility is to have a variable in your ViewController called something like isEditing
. This will be set to true when the edit button is clicked.
Then, set your collection view's delegate to self
.
Implement this method: func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath)
, A UICollectionViewDelegate method.
In the method, write something like:
if isEditing{
// What happens when selected and editing
} else{
// What happens when selected and not editing
}
Upvotes: 0