objective-c – 来自UICollectionView的按钮的索引路径

前端之家收集整理的这篇文章主要介绍了objective-c – 来自UICollectionView的按钮的索引路径前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试过了:
- (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]];
}

猜你在找的C&C++相关文章