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

查看:156
本文介绍了选择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];

解决方案是选择 值存储在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天全站免登陆