tableView设置UITableViewStyleGrouped非第一个section的间距失效

经实践必须全部实现以下的四个代理方法才有效(四个必须同时实现)

#pragma mark - ###### section的头部跟尾部的高度 #####
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    return 0 == section ? KIphoneSize_Height(10.0f) : 0.2;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
    return 0 == section ? KIphoneSize_Height(0.1f) : 0.2;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{

    if (section == 1) {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0.2f)];
        return view;
    }
    UIView *defaultView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, KIphoneSize_Height(0.1f))];
    defaultView.backgroundColor = defaultViewBgColor;
    return defaultView;
}


-  (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {

    if (section == 1) {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0.2f)];
        return view;
    }
    UIView *defaultView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, KIphoneSize_Height(0.1f))];
    defaultView.backgroundColor = defaultViewBgColor;
    return defaultView;
}

以下是表格初始化的代码

-(UITableView *)contectInfoTableView
{
    if (!_contectInfoTableView)
    {
        _contectInfoTableView = [[UITableView alloc] initWithFrame:CGRectMake(0.0, 0.0, kScreen_Width, kScreen_Height - KIphoneSize_Height(44.0f) - KIphoneSize_Height(80.0f)) style:UITableViewStyleGrouped];
        _contectInfoTableView.delegate = self;
        _contectInfoTableView.dataSource = self;
        _contectInfoTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    
    return _contectInfoTableView;
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • feisky云计算、虚拟化与Linux技术笔记posts - 1014, comments - 298, trac...
    不排版阅读 9,365评论 0 5
  • 这是16年5月份编辑的一份比较杂乱适合自己观看的学习记录文档,今天18年5月份再次想写文章,发现简书还为我保存起的...
    Jenaral阅读 7,977评论 2 9
  • 我的朋友小优一向活泼开朗,最近1个礼拜抑郁了。 昨天晚上小优跟我诉苦,说她最近1周相亲了10多个男生,但是1个也没...
    曾小容的职场圈阅读 4,249评论 1 8
  • 有时我一直搞不明白,现在也搞不明白。这个世界究竟怎么了,可谁有关心呢?那些道理其实我还是懂的,坚持锻炼身体,练就马...
    雪方明阅读 1,774评论 0 0
  • 每个人都需要有自我认知的潜意识。不能把满腔的怨愤归咎到自己和别人的身上。若是每天都怒气冲冲,长此以往,不仅是身心俱...
    糜子阅读 2,515评论 0 5