【发布时间】:2021-08-15 11:01:45
【问题描述】:
我将 UITableView 放在 UIScrollView > View > StackView 中。
我像往常一样在 View Controller 中使用 numberOfRowsInSection 和 cellForRowAt 实现了表格视图。这是我的扩展。
extension OrderViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
print("DEBUG: orderItems.count - \(orderItems.count)")
return orderItems.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: OrderCell.id, for: indexPath) as! OrderCell
cell.configure(orderItems[indexPath.row])
return cell
}
}
但我的模拟器实际上显示的是空单元格。我已经检查了 orderItems 数组只有 2 个成员。
我猜这是因为自动布局或堆栈视图。在堆栈视图中,我为除表格视图之外的每个视图提供了高度限制,因为它必须具有动态单元格编号。
我不知道我必须改变什么。
【问题讨论】:
-
我认为你需要给tableview设置高度约束,然后在重新加载tableview后使用tableview的数据更改高度约束。
标签: ios swift autolayout