我一开始的思路和这一篇文章差不多.大致思路是通过显示组头.将要显示组头的UITableView代理方法来判断最上层是哪个组头.思路是没有错误的,但是试玩了一下.在两个组切换之间.不松手的上下滑动会有BUG(具体表现为当前显示组头一直+1,+1,+1).
{
//使用currentTopSectionViewCount记录当前显示的最上层的Section.在控制器中初始化为0.
long _currentTopSectionViewCount;
}
最主要的是所有UIScrollView以及继承与UISCrollView子控件的已经滚动的代理.
以及当前显示的”Cells”.通过- (UITableViewCell *)visibleCells;
来调用.
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
if (scrollView == self.tableView) {
NSArray <ZGAccountsBookDataTableViewCell *> *cellArray = [self.tableView visibleCells];
//cell的section的最小值
long cellSectionMINCount = LONG_MAX;
for (int i = 0; i < cellArray.count; i++) {
ZGAccountsBookDataTableViewCell *cell = cellArray[i];
long cellSection = [self.tableView indexPathForCell:cell].section;
if (cellSection < cellSectionMINCount) {
cellSectionMINCount = cellSection;
}
}
_currentTopSectionViewCount = cellSectionMINCount;
NSLog(@"当前悬停的组头是:%ld",_currentTopSectionViewCount);
}
}