今天遇到个问题,tableView上的cell上一个button,现在想点击这个button获得这个tableView的indexPath.section。
于是在网络整理这个方法,希望对一些朋友有用。
- (void)deleteBtnClik:(UIButton *)sender {
TZTestCell *cell = (TZTestCell *)[sender superview];
//这一步要注意 [sender superview]类型不一定为cell,如果不是可以这样取值,视具体情况而定。
// UIView *v = [sender superview]; UIView *v2 = [v superview]; 依次取直到 po [[**** superview] class]类型为class
//TZTestCell *cell = (TZTestCell *)[**** superview];
__block NSIndexPath *indexPath = [self.pictureCollectionView indexPathForCell:cell];
[_pictureCollectionView performBatchUpdates:^{
NSIndexPath *indexPathDelete = [NSIndexPath indexPathForItem:sender.tag inSection:indexPath.section];
[_pictureCollectionView deleteItemsAtIndexPaths:@[indexPathDelete]];
} completion:^(BOOL finished) {
[_pictureCollectionView reloadData];
}];
}