思路是在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];
}