Xcode-9 beta 中的自动布局损坏
Autolayout broken in Xcode-9 beta
我的其中一个屏幕显示 UITableView
。它显示 headers 部分和具有 动态高度 的行。
当我从 Xcode8.3 移动到 Xcode-9 beta.
时,这个 set-up 有两个问题
1 Header 视图高度损坏
2 断行的动态高度
我 set-up 我的 table 观点是:
然后我有自定义单元格
代码如下:
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 设置时:
这种行为的原因是什么?
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 30.0
将此添加到您的 viewDidLoad
中,无需 tableview 委托方法 estimatedHeightForRowAt
。
我的其中一个屏幕显示 UITableView
。它显示 headers 部分和具有 动态高度 的行。
当我从 Xcode8.3 移动到 Xcode-9 beta.
1 Header 视图高度损坏
2 断行的动态高度
我 set-up 我的 table 观点是:
然后我有自定义单元格
代码如下:
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 设置时:
这种行为的原因是什么?
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 30.0
将此添加到您的 viewDidLoad
中,无需 tableview 委托方法 estimatedHeightForRowAt
。