【问题标题】:Wrong UITableViewAutomaticDimension height, only on iPhone 5错误的 UITableViewAutomaticDimension 高度,仅在 iPhone 5 上
【发布时间】:2018-08-07 10:15:58
【问题描述】:

我的tableview单元格的高度是自动计算的

tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = UITableViewAutomaticDimension

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

它在除 iPhone 5 之外的所有设备上都运行良好。在实际设备和模拟器中进行了尝试,结果相同:

任何想法为什么会发生? iOS 10.3.1

【问题讨论】:

  • 检查你的约束。
  • 试试 tableView.estimatedRowHeight = 10
  • 我同意@MaheshDangar
  • @TmGoyani >它在除 iPhone 5 之外的所有设备上都运行良好。限制是什么原因?
  • @Edward 如果您想在所有设备中实现动态高度,那么您必须设置适当的约束并在 heightForRow 中返回“UITableViewAutomaticDimension”。

标签: ios swift uitableview


【解决方案1】:

tableView.estimatedRowHeight = UITableViewAutomaticDimension 仅适用于 iOS 11。

改用实数值:

if #available(iOS 11.0, *) {
    tableView.estimatedRowHeight = UITableViewAutomaticDimension
} else {
    tableView.estimatedRowHeight = 200
}

【讨论】:

  • 不,这只是一个约束问题而不是版本控制问题因为 UITableViewAutomaticDimension 在 ios 5.0 之后可用
  • 您说的是在“rowHeight”中设置“UITableViewAutomaticDimension”而不是“estimatedRowHeight”。这是 iOS11 中的新功能。请正确阅读答案。
【解决方案2】:

估计的行高应该是单元格的平均高度。

【讨论】:

    【解决方案3】:

    您必须为估计的行高设置值,该值将是您的最小行高。 下面是一个例子......

    tableView.estimatedRowHeight = 44;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-28
      • 1970-01-01
      • 1970-01-01
      • 2012-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多