我正在尝试让我的 tableView cells
可移动,但它需要来自 UITableViewDataSource
协议(protocol)的 2 或 3 个函数,如果我试图在我的 中实现委托(delegate)viewController
它将请求 numberOfRowsInSection
和 cellForRowAtIndexPath
函数,新的 UITableViewDiffableDataSource
已经涵盖了这些函数。
如何在使用新的 UITableViewDiffableDataSource
时实现此行为?
最佳答案
我能够通过子类化 UITableViewDiffableDataSource
类来做到这一点,如下所示:
class MyDataSource: UITableViewDiffableDataSource<Int, Int> {
override func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
// your code to update source of truth
// make a new snapshot from your source of truth
// apply(snapshot, animatingDifferences: false)
}
}
然后您可以覆盖
实现所需的任何数据源方法。
关于ios - 如何在使用 UITableViewDiffableDataSource 时移动 UITableView 单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57510622/