【问题标题】:UITableViewAutomaticDimension return -1UITableViewAutomaticDimension 返回 -1
【发布时间】:2014-07-19 19:28:26
【问题描述】:

您好,我创建了 tableviewcontroller 类,我想动态获取单元格高度,所以我使用 UITableViewAutomaticDimension 但它总是返回-1。

    tableView.rowHeight = UITableViewAutomaticDimension
    println("\(tableView.rowHeight)")
    tableView.estimatedRowHeight = 44

当我执行 tableView.rowHeight = 44 时,一切正常。我的超类是 UIViewController。

【问题讨论】:

  • 您是否在单元格中添加了约束?
  • 不,我会添加它并写出结果它有帮助谢谢!
  • UITableViewAutomaticDimension 的值没有记录在案,但实际上它等于 -1。它被用作UITableView 的信号,它应该使用-systemLayoutSizeFittingSize: 找到单元格的高度

标签: ios swift ios8


【解决方案1】:

您只能将UITableViewAutomaticDimension 用于页脚/页眉高度,并且只有在您实现时:

- tableView:titleForHeaderInSection:

如果您正在实施:

- tableView:viewForHeaderInSection:

它不会工作。 UITableViewAutomaticDimension 不打算用于设置行高。使用rowHeight 并指定您的值或实施:

- tableView:heightForRowAtIndexPath:

【讨论】:

  • 对我的问题的评论有一个很好的答案,我们说的是swift而不是obj-c
  • @Bearwithme:这个说法还准确吗? * UITableViewAutomaticDimension 不用于设置行高*
  • @SwiftArchitect 不,它不再准确了。 UITableViewAutomaticDimension 现在也用于行高。
猜你喜欢
  • 2018-01-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-10
  • 2015-03-04
  • 2013-10-27
  • 2016-07-28
  • 2014-09-26
相关资源
最近更新 更多