我有一个表视图,看起来像这样:
data
.drive(tableView.rx.items(cellIdentifier: "cell")) { index, model, cell in
// update cell
}
.disposed(by: disposeBag)当用户选择一个单元格,然后数据发生变化时,rx-swift将重新加载表视图,所做的选择将丢失。
我确实有一个对所选indexPath的引用,但是设置选择的好方法是什么?
现在我唯一的想法是这样的:
data
.delay(0.2) // make shure this happens after the reload
.drive(onNext: { model in
// select tableview cell
})这显然很糟糕:-(
RxDataSources会解决这个问题吗?如果是,是如何实现的?
或者,有没有其他方法来保留这个选择?
发布于 2019-01-08 00:01:52
是的,RxDataSources会解决这个问题,或者你也可以自己解决。解决方案是只重新加载需要重新加载的单元格,而不是整个表视图。这是基本的RxCocoa系统所不能做到的。
为了解决这个问题,您需要一个自定义的DataSource。这是我用DifferenceKit编写的跟踪更改的代码。(https://github.com/dtartaglia/RxMultiCounter/blob/master/RxMultiCounter/RxExtensions/RxSimpleAnimatableDataSource.swift)
https://stackoverflow.com/questions/54077522
复制相似问题