Shmidt Shmidt - 4 months ago 11
Objective-C Question

Indexpath of the button from UICollectionView

I tried to:

- (IBAction)delete:(UIButton*)sender{
NSIndexPath *indexPath = [self.collectionView indexPathForCell:(TourGridCell *)[[[sender superview]superview]superview]];
}


But NSLog shows that cell exist, but indexpath is nil.

Answer

OK, here it is:

- (IBAction)delete:(UIButton *)sender{
    NSIndexPath *indexPath = nil;
    indexPath = [self.collectionView indexPathForItemAtPoint:[self.collectionView convertPoint:sender.center fromView:sender.superview]];
}