UITableView Not Respecting heightForHeaderInSection/heightForFooterInSection?

后端 未结 9 1663
臣服心动
臣服心动 2020-12-09 02:57

I have a UITableView where in some instances, certain sections have zero rows. My goal is that when this is true, I don\'t want any wasted space in the table view, it should

9条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-09 03:49

    It works for me:

    - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
    {
        tableView.sectionHeaderHeight = (section == 0 ? 10 : 0);
        return tableView.sectionHeaderHeight;
    }
    
    - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
    {
        tableView.sectionFooterHeight = (section == 0 ? 20 : 4);
        return tableView.sectionFooterHeight;
    }
    

提交回复
热议问题