1

UITableView在我的屏幕之一。它显示具有动态高度的节标题和行。
当我从 Xcode8.3 迁移到 Xcode-9 beta 时,这个设置有两个问题。

1 标题视图高度损坏
2 行的动态高度损坏

我已将表格视图设置为:

在此处输入图像描述 在此处输入图像描述

然后我有自定义单元格

在此处输入图像描述
在此处输入图像描述
在此处输入图像描述

这是代码:

func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
    return //dynamically calculated height according to msg text
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return 30
}

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    let headerHeight:CGFloat = tableView.sectionHeaderHeight
    let headerView = HeaderView(frame: CGRect(x: 0, y: 0, width: tableView.width, height: headerHeight), withHeaderLable: "Date/Day of msg")
    return headerView
}

即使有多行消息,这在 Xcode8.3 中也能完美运行,但在 Xcode9 beta 中被破坏为:当我在 Xcode9 beta 中使用 Swift3.2 设置运行时:

在此处输入图像描述

当我在 Xcode9 beta 中使用 Swift4 设置运行时:

在此处输入图像描述

这种行为的原因是什么?

4

1 回答 1

3
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 30.0

将此添加到您的viewDidLoad并且不需要 tableview 委托方法estimatedHeightForRowAt

于 2017-06-22T11:22:16.150 回答