SoySauceLab / CollectionKit

Reimagining UICollectionView
MIT License
4.4k stars 259 forks source link

CollectionView doesn't clear sometimes #85

Closed Banck closed 6 years ago

Banck commented 6 years ago

Hello! I've tried to create dummyCells and showing it, for example, first 5 sec and then clear collectionView and show real cells. But when I set new data some cells didn't remove from collectionView even I set empty array to dataSource:

var dummyModels: [Model] = []
        for _ in 0..<20 {
            let model = Model(object: [:])
            dummyModels.append(model)
        }
        dataSource.data = dummyModels

and after sometime call: dataSource.data = matches And on the screen I can see 2 empty cells and bellow them real cells: http://joxi.ru/D2P6pJspD1XQr3 http://joxi.ru/xAe8abupz6aY2y

If I call

dataSource.data.removeAll()

On the screen I can see 2 cells. I've debugged and dataSource.data.count == 0.

lkzhao commented 6 years ago

This is weird, can you provide more code. What presenter are you using. what kind of data source are you using?

Banck commented 6 years ago

@lkzhao Seems, I resolved this issue. I have datasource:

        dataSource = ArrayDataSource(data: presenter!.matches, identifierMapper: { (index, data) -> String in
            return "\(data.id ?? 0)"
        })

and when I want to create empty cell my data.id nil. So all cells had identifier == 0. And then when I call dataSource.data.removeAll() some cells still on the screen.

Now I have dataSource:

dataSource = ArrayDataSource(data: presenter!.matches, identifierMapper: { (index, data) -> String in
            return "\(data.id ?? index)"
        })

and all is fine.

lkzhao commented 6 years ago

@Banck Thanks for reporting. It shouldn't leave the cells on screen even if there are identifier conflicts. I will push a patch to fix this issue in next week. Please leave this open for now.