说我想限制表格视图的高度约束以仅显示特定数量的顶部单元格,如何获得它们的总高度?
答案 0 :(得分:-1)
快捷键5:
extension UITableView {
func height(of top: Int, in section: Int = 0) -> CGFloat {
let count = min(top, numberOfRows(inSection: section))
let height = (0..<count)
.map { IndexPath(row: $0, section: section) }
.map { self.rectForRow(at: $0).height }
.reduce(0, +)
return height
}
}
非常适合:
extension UITableView {
func reloadData(completion: @escaping () -> ()) {
CATransaction.begin()
CATransaction.setCompletionBlock(completion)
reloadData()
CATransaction.commit()
}
}
在数据加载后更新约束。