我把我的 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 具有与您的视图相关的全高。只需添加 viewDidLoad
yourTableView.tableFooterView = UIView()
但是,如果您想要 tableview 的动态高度,请执行此操作;
重新加载 tableview 后
heightConstraint.constant = yourRowHeight * arrayCount
self.view.layoutIfNeeded()
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句