Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UICollectionView delete button

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

like image 877
Typhoon101 Avatar asked Oct 08 '12 12:10

Typhoon101


1 Answers

Editing items in UICollectionViews 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.

like image 69
Guido Hendriks Avatar answered Oct 08 '22 01:10

Guido Hendriks