Reputation: 832
I have a tableview that looks something like this:
data
.drive(tableView.rx.items(cellIdentifier: "cell")) { index, model, cell in
// update cell
}
.disposed(by: disposeBag)
When a user selects a cell and then the data changes rx-swift will reload the table view and the selection is lost.
I do have a reference to the selected indexPath but what is a nice way to set the selection?
For now my only idea would be something like this:
data
.delay(0.2) // make shure this happens after the reload
.drive(onNext: { model in
// select tableview cell
})
Which obviously sucks :-(
Will RxDataSources solve this problem? If yes how?
Or are there any other ways to keep this selection?
Upvotes: 1
Views: 771
Reputation: 33967
Yes, RxDataSources will solve the problem, or you can roll your own. The solution is to only reload the cells that need reloading instead of the entire table view. This is something that the basic RxCocoa system doesn't do.
To solve the problem, you need a custom DataSource. Here is one I wrote using DifferenceKit to track changes. (https://github.com/dtartaglia/RxMultiCounter/blob/master/RxMultiCounter/RxExtensions/RxSimpleAnimatableDataSource.swift)
Upvotes: 1