UICollectionView multiple Selection Reusability issue

有些话、适合烂在心里 提交于 2020-01-06 17:41:31

问题


I am new to UICollectionview. I have made a simple sample were I can apply multiple selection of image. but I'am getting issue regarding selection, the issue is when I scroll collection view the check mark are added to other cells and the images array count is different at didSelectedItem and didDeselectItem.

Here is the sample code which i have tried Sample Link


回答1:


When you scroll in a CollectionView (or a in TableView for that matter), the cells are reused.
To keep the selection while scrolling you need to keep an array of the selected IndexPaths and update the cells accordingly in your collectionView:cellForItemAtIndexPath:. That means removing the checkmark or setting it if the selected array contains this IndexPath.



来源:https://stackoverflow.com/questions/26420356/uicollectionview-multiple-selection-reusability-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!