No delegate methods provided to UICollectionViewController as like UITableviewController.
We can do it manually by adding a long gesture recognizer to UICollectionView.
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self
action:@selector(activateDeletionMode:)];
longPress.delegate = self;
[collectionView addGestureRecognizer:longPress];
In longGesture method add button on that particular cell.
- (void)activateDeletionMode:(UILongPressGestureRecognizer *)gr
{
if (gr.state == UIGestureRecognizerStateBegan) {
if (!isDeleteActive) {
NSIndexPath *indexPath = [collectionView indexPathForItemAtPoint:[gr locationInView:collectionView]];
UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
deletedIndexpath = indexPath.row;
[cell addSubview:deleteButton];
[deleteButton bringSubviewToFront:collectionView];
}
}
}
In that button action,
- (void)delete:(UIButton *)sender
{
[self.arrPhotos removeObjectAtIndex:deletedIndexpath];
[deleteButton removeFromSuperview];
[collectionView reloadData];
}
I think it can help you.