UICollectionView 多选重用问题 [英] UICollectionView multiple Selection Reusability issue

查看:38
本文介绍了UICollectionView 多选重用问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 UICollectionview 的新手. 我做了一个简单的示例,我可以应用多个图像选择.但我遇到了关于选择的问题,问题是当我滚动集合视图时,复选标记被添加到其他单元格,并且图像数组计数在 didSelectedItemdidDeselectItem 处不同.

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

推荐答案

当您在 CollectionView(或 TableView 中的一个)中滚动时,单元格是重用.
要在滚动时保留选择,您需要保留所选 IndexPaths 的数组,并相应地更新 collectionView:cellForItemAtIndexPath: 中的单元格.这意味着如果选定的数组包含此 IndexPath,则删除复选标记或设置它.

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.

这篇关于UICollectionView 多选重用问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆