UITableView internal inconsistency: _visibleRows and _visibleCells must be of same length

in my case it was due to editing tableview on background queue use your updating method like this DispatchQueue.main.async { [weak self] in self?.updateUI() }


I had the same issue and noticed that I was forcing reload the tableView during cell creation via a protocol fired by the cell.

The Problem:

    // ViewController: CellDelegate
        func onFirstUpdate(state: Bool){
          self.moreInfoHidden = state
          self.tableView.beginUpdates()
          self.tableView.endUpdates()
        }

        func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

                let cell = self.tableView.dequeueReusableCell(withIdentifier: "MyTableViewCell", for: indexPath) as! MyTableViewCell
                cell.refresh(self.data)
                cell.delegate = self
                return cell
...

    // MyTableViewCell
    self.firstUpdate = true
    func refresh(_ data: MyItem){
       if firstUpdate{
          self.delegate.onFirstUpdate(true)
          self.firstUpdate = false
       }
    }

The Solution:

1. Removing tableview update as i understood it is not necessary in my case
           func onFirstUpdate(state: Bool){
              self.moreInfoHidden = state
              //self.tableView.beginUpdates()
              //self.tableView.endUpdates()
            }

2. (Not recommended because of degrading performance) Reload whole table properly again. 

       func onFirstUpdate(state: Bool){
          self.moreInfoHidden = state
          self.tableView.reloadData()
        }