Search code examples
objective-cios6uicollectionview

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.


Solution

  • OK, here it is:

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