美文网首页
怎么让tableview最上面的分区悬浮并展示当前分区的内容,其

怎么让tableview最上面的分区悬浮并展示当前分区的内容,其

作者: 这个姑凉儿 | 来源:发表于2022-05-07 17:46 被阅读0次

思路是在tableview上面放个固定的view来实现,哪个分区滑动到最上面了,就把当前的标题展示

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{

    [self getNowTopSectionView];

}
// 获取tableView最上面悬停的SectionHeaderView
- (void)getNowTopSectionView {
    NSArray <UITableViewCell *> *cellArray = [self.tableView visibleCells];
    NSInteger nowSection = -1;
    if (cellArray) {
        UITableViewCell *cell = [cellArray firstObject];
        NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
        nowSection = indexPath.section;
    }
    NSLog(@"当前悬停的组头是:%ld",nowSection);
    self.bb.text = [NSString stringWithFormat:@"当前是第%ld个分区",nowSection];
}

相关文章

网友评论

      本文标题:怎么让tableview最上面的分区悬浮并展示当前分区的内容,其

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