tableview使用group格式的時(shí)候,會(huì)自帶一個(gè)headview以及footview,如果不設(shè)置這兩個(gè)的高度,他們會(huì)默認(rèn)有一個(gè)44的高度统抬,這會(huì)行程一些困擾。
而plain格式的時(shí)候危队,headview會(huì)不斷的保留在tableview的頂部
一聪建、UITableViewStylePlain
1.有多段時(shí) 段頭停留(自帶效果)
2.沒有中間的間距和頭部間距(要想有的重寫UITableViewCell \UITableViewHeaderFooterView里面的setFrame方法)
擴(kuò)展:讓段頭不停留(取消粘性效果)
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat sectionHeaderHeight = 30;
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);
}
}
二、UITableViewStyleGroup
注意:去掉頭部和中間間隔
正確的理解方法
1.設(shè)置標(biāo)頭的高度為特小值 (不能為零 為零的話蘋果會(huì)取默認(rèn)值就無法消除頭部間距了)
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 0.001)];
view.backgroundColor = [UIColorredColor];
self.tableView.tableHeaderView = view;
2.寫代理方法(中間的留白其實(shí)是段尾的高度 代理的作用設(shè)置段尾的高度 返回值也不能為0)
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 0.01f;
}
特殊的處理方法也能實(shí)現(xiàn)該效果
1. ? ?self.tableView.contentInset = UIEdgeInsetsMake(-44, 0, 0, 0);
2.重寫UITableViewHeaderFooterView的
-(void)setFrame:(CGRect)frame{
frame.size.height+=10;
[super setFrame:frame];
}