我正在尝试在选择行后在部分之间移动项目。 这是我用于将项目从第 0 节移动到第 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 用于在动画后更新行。
如果所有项目都适合屏幕或第 1 部分可见,则它会完美运行。否则,我得到的行为就像您删除一行并将其添加到另一个索引时一样。
最佳答案
这是因为如果单元格不可见,UITableView 不知道在哪里设置动画
关于ios - 移动行(在 :to:) doesn't work if the UITableView has many items,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42665992/