tableView的cell上有一个button,或者其他控件,我们怎么知道他是哪个section

来源:互联网 发布:英特尔人工智能大会 编辑:程序博客网 时间:2024/05/07 13:29

今天遇到个问题,tableView上的cell上一个button,现在想点击这个button获得这个tableView的indexPath.section。

于是在网络整理这个方法,希望对一些朋友有用。

- (void)deleteBtnClik:(UIButton *)sender {

    TZTestCell *cell = (TZTestCell *)[sendersuperview];

   //这一步要注意 [sender superview]类型不一定为cell,如果不是可以这样取值,视具体情况而定。

   // UIView *v = [sender superview]; UIView *v2 = [v superview]; 依次取直到 po [[**** superview] class]类型为class

   //TZTestCell *cell = (TZTestCell *)[**** superview];

   __blockNSIndexPath *indexPath = [self.pictureCollectionViewindexPathForCell:cell];

    

    [_pictureCollectionViewperformBatchUpdates:^{

        NSIndexPath *indexPathDelete = [NSIndexPathindexPathForItem:sender.taginSection:indexPath.section];

        [_pictureCollectionViewdeleteItemsAtIndexPaths:@[indexPathDelete]];

    } completion:^(BOOL finished) {

        [_pictureCollectionViewreloadData];

    }];

}


阅读全文
0 0