【问题标题】:Swift 3: How can I remove the extra space from the TableView?Swift 3:如何从 TableView 中删除多余的空间?
【发布时间】:2017-08-01 00:30:09
【问题描述】:

我在 tableview 上有一个 webview,在每个单元格上,我在电话号码和电子邮件/网站地址之后都有一些额外的空白。那么如何从单元格中删除/删除多余的空白空间以使其看起来更好。

我的代码是这样的:

self.heightOfTheCell = CGFloat(((heightMul)*32)+4)

我不太清楚如何处理这些数字。

请查看随附的屏幕截图。

 func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {

    if indexPath.section == 0
    {
        if heightOfTheCell != nil
        {
            return heightOfTheCell
        }else{
            return UITableViewAutomaticDimension
        }
    }
    else{
        return UITableViewAutomaticDimension
    }



}


func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {


        return UITableViewAutomaticDimension
}

【问题讨论】:

    标签: uitableview swift3 uiwebview autolayout


    【解决方案1】:

    这就是我的做法。

    首先正确设置单元格的约束。

    然后在你的 viewController 上

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return UITableViewAutomaticDimension
    }
    
    
    func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
        return UITableViewAutomaticDimension
    }
    

    【讨论】:

    • 似乎heightOfTheCell 使高度保持不变,您可以尝试将其删除并仅删除UITableViewAutomaticDimension 吗?如果问题仍然存在,则单元格中可能存在将高度强制为特定值的约束。无论如何,这是我学会动态设置单元格高度的地方。 raywenderlich.com/129059/self-sizing-table-view-cells
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-19
    • 2020-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多