tableview去除headerview和footer view有两种方法:
第一种方法,直接创建tableview时选择style为grouped;(默认为plain)
第二种方法:
同时去除headerview和footer view,
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView == self.listTableView) {
UITableView *tableview = (UITableView *)scrollView;
CGFloat sectionHeaderHeight = kCellSectionHeaderHeight;
CGFloat sectionFooterHeight = kCellSectionFooterHeight;
CGFloat offsetY = tableview.contentOffset.y;
if (offsetY >= 0 && offsetY <= sectionHeaderHeight)
{
tableview.contentInset = UIEdgeInsetsMake(-offsetY, 0, -sectionFooterHeight, 0);
}else if (offsetY >= sectionHeaderHeight && offsetY <= tableview.contentSize.height - tableview.frame.size.height - sectionFooterHeight) {
tableview.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, -sectionFooterHeight, 0);
}else if (offsetY >= tableview.contentSize.height - tableview.frame.size.height - sectionFooterHeight && offsetY <= tableview.contentSize.height - tableview.frame.size.height) {
tableview.contentInset = UIEdgeInsetsMake(-offsetY, 0, -(tableview.contentSize.height - tableview.frame.size.height - sectionFooterHeight), 0);
}
}
}
若只去除headerview,
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView == self.listTableView) {
CGFloat sectionHeaderHeight = kCellSectionHeaderHeight;
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);
}
}