【问题标题】:Reduce space between header and table view cell in swift快速减少标题和表格视图单元格之间的空间
【发布时间】:2021-01-07 10:53:29
【问题描述】:

我有一个带有自定义标题的表格视图和一个带有单个部分的单元格。 我想减少标题和第一个单元格之间的空间。 我使用了heightforrow方法如下:

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        if tableView == tableview1
        {
            return 1
        }
        else
        {
            return 0
        }
    }

这对间距没有任何影响。 标题的高度是 774。单元格从 798 开始,如图所示呈灰色。

如何减少它的空间如下图所示。

【问题讨论】:

    标签: swift uitableview header tableview space


    【解决方案1】:

    尝试使用 Float.leastNonzeroMagnitude 代替零

    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        if tableView == tableview1
        {
            return CGFloat(Float.leastNonzeroMagnitude)
        }
        else
        {
            return 0
        }
    }
    

    【讨论】:

    • 这 1 没有帮助。我只想要 tableview1
    • 更新了我的答案,如果没有解决,你可以在索引路径委托方法中分享你的行高
    • 我没有使用过那个委托方法
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-10
    • 2019-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多