-
Notifications
You must be signed in to change notification settings - Fork 498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incremental adding element to a SectionModel cause duplicate item issue #251
Comments
What is a |
I have the same problem, almost identical code @ZZHHAANNGG did you manage to figure it out? |
i have the same question, where can i set a different id ? |
I have the same one. |
Same |
@ZZHHAANNGG, Can you paste the implementation details for Anyone who's having issues, there's definitely a reason why the Differentiator thinks the item has been added and it is most likely to do with the item's identity. It has to be unique for each item. |
import RxCocoa
import RxSwift
import RxKingfisher
import Differentiator
struct ItemExploreCellViewModel {
let username: Driver<String>
let userPic: Observable<URL?>
let title: Driver<String>
let description: Driver<String>
let wishedCount: Driver<String>
let imageURL: Driver<[String?]>
let isWanted: Driver<Bool>
let itemId: Int
let isOwner: Driver<Bool>
let item: ItemInfo
init (item: ItemInfo, userId: Int) {
self.item = item
self.itemId = item.id
self.username = Driver.just(item.swapperByOwnerId?.username ?? "")
self.userPic = Observable.just(item.swapperByOwnerId?.profilePicture ?? "https://images.crowdswap.com/octavio.png").map { URL(string: $0) }
self.title = Driver.just(item.name ?? "")
self.description = Driver.just(item.description ?? "")
self.wishedCount = Driver.just(item.countWants ?? "")
self.imageURL = Driver.just(item.pictures ?? ["https://i0.wp.com/oij.org/wp-content/uploads/2016/05/placeholder.png"])
self.isWanted = Driver.just(item.isWanted ?? false)
self.isOwner = Driver.just(item.swapperByOwnerId?.id == userId)
}
}
extension ItemExploreCellViewModel: IdentifiableType {
typealias Identity = Int
var identity: Int {
return item.id
}
}
extension ItemExploreCellViewModel: Equatable {
static func == (lhs: ItemExploreCellViewModel, rhs: ItemExploreCellViewModel) -> Bool {
return lhs.item.id == rhs.item.id &&
lhs.item.name == rhs.item.name &&
lhs.item.description == rhs.item.description &&
lhs.item.countWants == rhs.item.countWants &&
lhs.item.pictures == rhs.item.pictures
}
} |
Did you find a workaround? |
I have a one section array. Whenever the user scrolls up the tableview, it loads the additional prefetched data from an API and adds the identical data to the end of the AnimatableSectionModelType Item. The section header is always an empty string. It crashes because there is a duplicate item at Indexpath(0,0).
Item CustomerJSON(UserId: Optional("016f0166-ead2-4719-88be-3f3bc45677c1"), UserName: Optional("13923715796"), CreateTime: Optional("2017/6/8 23:38:53"), GoodsCount: Optional(0), GoodsPrice: Optional(0.0)) has already been indexed at (0, 0)
What do I miss?
The data looks this
The text was updated successfully, but these errors were encountered: