美文网首页
18.获取被点击的tablview的sectionHeader的

18.获取被点击的tablview的sectionHeader的

作者: 枫之叶_小乙哥 | 来源:发表于2020-06-20 18:17 被阅读0次

1.获取sectionHeader的indexPath

苹果系统提供了indexPathForRowAtPoint:方法, 用来获取当前的点所在cell的indexPath, 但是如果传入的是sectionHeader的坐标,则返回的indexPath是nil, 因此该方法无法获取sectionHeader的indexPath.

我们可以换种思路, 通过获取sectionHeader下的第一个cell来获取当前sectionHeader的indexPath, 方法如下:


//  使用sectionHeader的frame往下一个点,作为point传入,获取到sectionHeader下的第一个cell的indexPath
 NSIndexPath *indexPath = [self.tableV indexPathForRowAtPoint:CGPointMake(CGRectGetMinX(headerView.frame), CGRectGetMaxY(headerView.frame) + 1)];

这里,我们需要对最后一个sectionHeader(如果不存在cell的情况)进行处理


// kFitWidth(45)是sectionHeaderView的高度
// 最后一个sectionHeaderView要特殊处理,才能获取到准确的section
if (indexPath == nil && self.dataSource.count > 0 && CGRectGetMaxY(headerView.frame) > kFitWidth(45)) {  
        indexPath = [NSIndexPath indexPathWithIndex:self.dataSource.count];
    }

  [self updateMixedActionViewConstraintsWithSection:indexPath.section showBlock:nil hideBlock:^{
        self.mixedActionV.hidden = YES;
    }];

相关文章

网友评论

      本文标题:18.获取被点击的tablview的sectionHeader的

      本文链接:https://www.haomeiwen.com/subject/clsgxktx.html