Swift 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()
}
}
для обновления ограничения после загрузки данных.