我试过了:
- (IBAction)delete:(UIButton*)sender{ NSIndexPath *indexPath = [self.collectionView indexPathForCell:(TourGridCell *)[[[sender superview]superview]superview]]; }
但NSLog显示单元格存在,但indexpath为零.
解决方法
好的,这是:
- (IBAction)delete:(UIButton *)sender{ NSIndexPath *indexPath = nil; indexPath = [self.collectionView indexPathForItemAtPoint:[self.collectionView convertPoint:sender.center fromView:sender.superview]]; }