ios - 移动行(在 :to:) doesn't work if the UITableView has many items

标签 ios swift uitableview animation swift3

我正在尝试在选择行后在部分之间移动项目。 这是我用于将项目从第 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/

相关文章:

ios - 来自 NSArray 的 NSMutableArray

swift - 顶层不允许使用表达式

iPhone 开发 - 如何捕获异常 'NSRangeException'

ios - 在多次删除行时删除 UITableView 上的行中的错误

iphone - 如何实现 "What' s Pic"iPhone 应用程序像砖 block 动画?

xcode - 为 RxSwift 编写单元测试

ios - 使用核心数据,我得到一个错误 'nib but didn’ t get a UICollectionView。

objective-c - 在 UITableView 列表 segue 之间传递索引号

ios - 无法为 UITableView 创建框架

ios - 如何使用 Mantle 在 NSArray 中指定子对象类型