去除UITableViewheader footer黏性

823 阅读1分钟

项目中遇到问题,如何去除tableview的headerview和footerview黏性。 这里有两种解决方案 1.最简单的方案 设置UITabeview的样式为UITableViewStyleGrouped 2.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    //解决header黏性
    CGFloat sectionHeaderHeight = 100;// head的高度
    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);
    }
}

还有一种方法 :

// 分区foot返回高度

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
        return 10;
}
//分组 底部
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}