当我从数据库加载数据并第一次调用 tableView.reloadData()
和 tableHeightConstraint.constant = tableView.contentSize.height
时,它工作得很好。但是当我添加新单元格并再次执行此操作时,它不起作用。没有 tableHeightConstraint.constant = tableView.contentSize.height
可以工作,但我无法更改 tableView
的高度。更改 tableView
高度非常重要。
最佳答案
UITableView并不是一个简单的UIScrollView,它的ContentSize来自当前 View 屏幕中的单元格,而不是所有单元格。
如果您在当前 View 边界之外添加单元格,则不会更改 ContentSize。
关于swift - 更改表格 View 高度后,CellForRowAt 不会调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39760273/