iOS—怎样让UITableView的表头随着tableView一起滚动?这样解决

来源:互联网 发布:python cmdb django 编辑:程序博客网 时间:2024/06/05 18:01

情况一:只有一个表头,在table的最上边

使用setTableHeaderView方法,会让头部跟着table向上移动消失。

不需要再添加“heightForHeaderInSection”、“titleForHeaderInSection和“viewForHeaderInSection”这三个方法

当然,如果你想让这个表头不消失,那就使用另外三个方法,只需要判断是第一个section就行了。


情况二:每个section都有header view(表示栏目信息的)

添加如下代码:

//去掉UItableview headerview黏性  ,table滑动到最上端时,header view消失掉。- (void)scrollViewDidScroll:(UIScrollView *)scrollView {      if (scrollView == self.myTableView)      {          CGFloat sectionHeaderHeight = YOUR_HEIGHT;          if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {              scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);          } else if (scrollView.contentOffset.y>=sectionHeaderHeight) {              scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);          }      }  } 


0 0
原创粉丝点击