- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section 组头将要出现的时候系统会调用;
- (void)tableView:(UITableView *)tableView didEndDisplayingHeaderView:(UIView *)view forSection:(NSInteger)section 组头出现的时候系统会调用;
利用以上两个方法可以判断出组头被顶出和组头又下拉回来事件,还有其他的组头相关动作可以监听需自己去编写。
_currentSection:当前显示的组头
_isUpScroll:是否是上拉滚动
_isFirstLoad:是否第一次加载tableView
_oldY:滚动的偏移量
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section{
if(!_isUpScroll && (_currentSection - section) == 1){
//最上面组头(不一定是第一个组头,指最近刚被顶出去的组头)又被拉回来
_currentSection = section;
NSLog(@"willDisplayHeaderView显示第%ld组",(long)section);
}
}
- (void)tableView:(UITableView *)tableView didEndDisplayingHeaderView:(UIView *)view forSection:(NSInteger)section{
if(!_isFirstLoad && _isUpScroll){
_currentSection = section + 1;
//最上面的组头被顶出去
NSLog(@"didEndDisplayingHeaderView显示第%ld组",(long)section + 1);
}
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
if ([scrollView isEqual: self.tableView]) {
if (self.tableView.contentOffset.y > _oldY) {
// 上滑
_isUpScroll = YES;
NSLog(@"上滑");
}
else{
// 下滑
_isUpScroll = NO;
NSLog(@"下滑");
}
_isFirstLoad = NO;
}
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
// 获取开始拖拽时tableview偏移量
_oldY = self.tableView.contentOffset.y;
}
iOS监听tableView组头切换事件
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 1. 如果不注册组头view 那么[tableView headerViewForSection:next1];获...
- 前言:创建一个UIiewController同时带有xib,xib中添加tableview,设置成分组模式。 问题...
- 需求:表头上显示文字 两种方案:系统给我们提供了tableViewController的代理方法返回组头/组尾文字...
- 背景介绍: 项目中的一个tableView要添加一个头部视图,组头是要跟着cell一起滚动的... 分析解决问题思...