MoveRow (at: to :) does not work if the UITableView has many elements

I am trying to animate the movement of elements between sections after selecting a row. This is the code that I use to move elements from section 0 to section 1:

tableSource[indexPath.section].tableItems.remove(at: indexPath.row)
tableSource[1].tableItems.insert(data, at: 0)
tableView.moveRow(at: indexPath, to: IndexPath(row: 0, section: 1))
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2, execute: {
    self.tableView.reloadRows(at: [IndexPath(row: 0, section: 1)], with: UITableViewRowAnimation.automatic)
 })

DispatchQueue is used to update the line after the animation.

It works fine if all the elements fit the screen or section 1 is visible. Otherwise, I get behavior when you delete a row and add it to another index.

+4
source share
1 answer

This is because the UITableView does not know where to animate if the cell is not visible

+3
source

Source: https://habr.com/ru/post/1671783/


All Articles