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.
source
share