Swift 3:如何从TableView中删除额外的空间?

问题描述:

我有一个webview的桌面视图,并在每个单元格我有一些额外的空白后的电话号码和电子邮件/网站地址。那么,如何从单元中删除/删除多余的空白区域,使其看起来更好一些。Swift 3:如何从TableView中删除额外的空间?

的代码是什么我是这样的:

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

我也不太清楚如何使用这些数字玩了。

请查看附件。

enter image description here

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 
} 

这里是我如何做到这一点。

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

那么您的viewController

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


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

看来'heightOfTheCell'正在高度不变,你可以尝试删除它,只是'UITableViewAutomaticDimension'? 如果问题仍然存在,也许在单元格中存在一个限制,将高度强制为特定值。通过任何方式,这里是我学会了动态设置单元高度的地方。 https://www.raywenderlich.com/129059/self-sizing-table-view-cells – Kiester