来自UICollectionView的按钮的索引路径

Shm*_*idt 7 objective-c ios6 uicollectionview

我试过了:

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

但NSLog显示单元格存在,但indexpath为零.

Shm*_*idt 26

好的,这是:

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