RxSwiftCommunity / RxDataSources

UITableView and UICollectionView Data Sources for RxSwift (sections, animated updates, editing ...)
MIT License
3.08k stars 494 forks source link

Fatal error: Duplicate item ... #353

Open nickfl opened 4 years ago

nickfl commented 4 years ago

Log shows first:

Item <HD_Rx.TrackItemPresentable: 0x6000034ab980> has already been indexed at (0, 33)
Fatal error: Duplicate item <HD_Rx.TrackItemPresentable: 0x6000034ab980>: file
..../Pods/RxDataSources/Sources/RxDataSources/DataSources.swift, line 32

Where TrackItemPresentable is part of TrackSection = AnimatableSectionModel<String, TrackItemPresentable>

Binding is done standard way:

    viewModel.sectionedItems
      .bind(to: tableView.rx.items(dataSource: dataSource))
      .disposed(by: self.rx.disposeBag)

where var sectionedItems: Observable<[TrackSection]>

And app crashes on the next update of sectionedItems.

nickfl commented 4 years ago

OK, I kinda fixed it. The problem was in dataSource: .bind(to: tableView.rx.items(dataSource: dataSource))

as looks like dataSource keeps all previous data. Maybe there is a method to flush it, but I couldn't find it.

So, I got rid of it and used a more direct binding on the go:

 .bind(to: tableView.rx.items(cellIdentifier: ResultTableViewCell.reuseId)) { row, model, cell in
     (cell as ResultTableViewCell).configureCell(track: model)
 }