UITableView Not Respecting heightForHeaderInSection/heightForFooterInSection?

后端 未结 9 1665
臣服心动
臣服心动 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:43

    I use the following solution:

    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return section == 0 ? CGFloat.leastNormalMagnitude : 8
    }
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0
    }
    

    Result:

提交回复
热议问题