我有一个表格 View ,其中填充了来自 Firebase 的数据。 但是,当使用自动尺寸调整表格 View 大小时,某些文本显示被截断。
这是我的 Storyboard,其约束设置为顶部、底部、右侧和左侧。
当没有大量文本时,它工作正常,如此处所示。
但是,当我用大量文本填充单元格时,就会发生这种情况。
这是我目前正在使用的代码。
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if (tableView == questInformationTableView) {
return 50
}
else if (tableView == questWalkthroughTableView) {
return UITableView.automaticDimension
}
return 0
}
override func viewDidLoad() {
super.viewDidLoad()
questWalkthroughTableView.estimatedRowHeight = 250
questWalkthroughTableView.rowHeight = UITableView.automaticDimension
}
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension
}
我还将 numberOfLines 设置为 0 并将标签设置为 .sizeToFit()
最佳答案
不要让底部约束大于或等于只是像顶部约束一样设置它。去掉 estimatedHeightForRowAt
和 heightForRowAt
函数。您的观点确实加载声明就足够了。当您重新加载数据时,还会调用 self.view.layoutIfNeeded
关于ios - UITableView 自动维度无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53325013/