问题描述
我有一个带有自定义标题的表格视图和一个带有单节的单元格。 我想减少标题和第一个单元格之间的空间。 我使用了 heightforrow 方法如下:
func tableView(_ tableView: UITableView,heightForHeaderInSection section: Int) -> CGFloat {
if tableView == tableview1
{
return 1
}
else
{
return 0
}
}
这对间距没有任何影响。 标题的高度为 774。单元格从 798 开始,如图所示变灰。
如何减少它的空间,如下所示。
解决方法
尝试使用 Float.leastNonzeroMagnitude 而不是零
func tableView(_ tableView: UITableView,heightForHeaderInSection section: Int) -> CGFloat {
if tableView == tableview1
{
return CGFloat(Float.leastNonzeroMagnitude)
}
else
{
return 0
}
}