# UITableViewStylePlain和UITableViewStyleGrouped的區(qū)別

UITableViewStylePlain和UITableViewStyleGrouped的區(qū)別

UITableViewStylePlain

1.有多段時(shí) 段頭停留(自帶效果)

2.沒(méi)有中間的間距和頭部間距(要想有的重寫(xiě)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)頭的高度為特小值 (不能為零 為零的話蘋(píng)果會(huì)取默認(rèn)值就無(wú)法消除頭部間距了)

UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 0.001)];
view.backgroundColor = [UIColor redColor];
self.tableView.tableHeaderView = view;

2.寫(xiě)代理方法(中間的留白其實(shí)是段尾的高度 代理的作用設(shè)置段尾的高度 返回值也不能為0)

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 0.01f;
}

特殊的處理方法也能實(shí)現(xiàn)該效果

方法一:

self.tableView.contentInset = UIEdgeInsetsMake(-44, 0, 0, 0);

方法二:重寫(xiě)UITableViewHeaderFooterView的

-(void)setFrame:(CGRect)frame{
frame.size.height+=10;
[super setFrame:frame];
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容