选择 UICollectionView iOS 中的所有项目,甚至是不可见的单元格 [英] Selecting all the items in UICollectionView iOS, even the cells that are not visible

查看:11
本文介绍了选择 UICollectionView iOS 中的所有项目,甚至是不可见的单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个应用程序,我在工具栏上有一个按钮,可以选择集合视图中的所有项目.

I am in the middle of creating an application where I have a button on a tool bar which selects all the items inside a collection view.

但我面临的问题是,当我点击按钮时,它只会选择那些在屏幕上可见的项目.这是由于 CELL REUSE 功能造成的.

But the problem that I am facing is, when I tap on the button it selects only those items that are visible on the screen. This is due to the CELL REUSE functionality.

有什么方法可以选择所有单元格,即使是当前对用户不可见的单元格?

Is there any way that I can select all the cells, even those which are not currently visible to the user?

谢谢J

推荐答案

使用单元格重用时不可能选择所有单元格.

It is not possible to have all cells selected when using cell reuse.

由于单元重用,在任何时候存在的实际单元的数量比当前可见的单元的数量多几个.即可见的 6 个单元格大约存在 8 个单元格.

Due to cell reuse the number of actual cells which exist at any moment is a couple more than the number of cells currently visible. i.e. 6 cells visible is about 8 cells existing.

您可以找出有多少可见单元格

You are able to find out how many visible cells there are with

NSArray *visiblePaths = [self.collectionView indexPathsForVisibleItems];

解决方案是将 selected 值存储在 UICollectionView 数据源中,并在自定义 cellForItemAtIndexPath

The solution is to have the selected value stored within the UICollectionView datasource and use that value for when you customise a cell inside cellForItemAtIndexPath

这篇关于选择 UICollectionView iOS 中的所有项目,甚至是不可见的单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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