zoukankan      html  css  js  c++  java
  • iOS监听tableView组头切换事件

    - (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;

    }

  • 相关阅读:
    HDU 1124 Factorial
    hdu 1690 Bus System
    hdu 1113 Word Amalgamation
    POJ 2482 Stars in Your Window
    hdu 1385 ZOJ 1456 Minimum Transport Cost(经典floyd)
    hdu 1907 John
    VMware 虚拟机 安装 UBuntu 9.10 命令模式转换成窗口模试
    #pragma CODE_SEG __NEAR_SEG NON_BANKED详解
    Ubuntu 下Hadoop 伪分布式 hadoop0.20.2.tar.gz 的安装
    文件拷贝代码以及疑问
  • 原文地址:https://www.cnblogs.com/piaojin/p/5945095.html
Copyright © 2011-2022 走看看