I have a UICollectionView showing several items. I also have an edit button in the screen toolbar.
How can I have delete icons appear on each UICollectionViewCell when I press the toolbar edit button?
There is very little in the way of examples on google at the moment, so if anyone can point me in the right direction, that would be great.
Thanks
Editing items in UICollectionView
s aren't done the same way as they're done in a UITableView
. In table views, there's a editing mode that'll show the delete button. But with collection views you gotta take care of that yourself.
Initially, I solved it this way:
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
if (self.editing) {
// Open an action sheet with the possible editing actions
}
}
But after that I removed the edit button and added a UILongPressGestureRecognizer
to the UICollectionView
. When long pressing an item I show the UIActionSheet
that shows the possible actions.
One of those options might be a possibility for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With