class TableViewReloadTestViewController: UIViewController { private lazy var tableView: UITableView = UITableView() override func viewDidLoad() { super.viewDidLoad() tableView.frame = view.frame view.addSubview(tableView) tableView.dataSource = self tableView.delegate = self } } extension TableViewReloadTestViewController: UITableViewDataSource, UITableViewDelegate { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 100 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { print("cellForItemAt \(indexPath)") let cell = UITableViewCell(style: .default, reuseIdentifier: nil) cell.textLabel?.text = "Row \(indexPath.row)" let redView = UIView() cell.contentView.addSubview(redView) redView.backgroundColor = .red.withAlphaComponent(0.1) redView.translatesAutoresizingMaskIntoConstraints = false cell.contentView.addConstraints([ .init(item: redView, attribute: .left, relatedBy: .equal, toItem: cell.contentView, attribute: .left, multiplier: 1.0, constant: 8.0), .init(item: redView, attribute: .right, relatedBy: .equal, toItem: cell.contentView, attribute: .right, multiplier: 1.0, constant: -8.0), .init(item: redView, attribute: .top, relatedBy: .equal, toItem: cell.contentView, attribute: .top, multiplier: 1.0, constant: 8.0), .init(item: redView, attribute: .bottom, relatedBy: .equal, toItem: cell.contentView, attribute: .bottom, multiplier: 1.0, constant: -8.0) ]) let heightConstraint = NSLayoutConstraint(item: redView, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: 100.0) heightConstraint.priority = .defaultLow redView.addConstraint(heightConstraint) return cell } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { //let randomRow = (0.. CGFloat { // log the calls print("estimatedHeightForRowAt ", indexPath) return 10 } }