简体   繁体   English

如何使uicollectionview不使单元出队?

[英]How can I make the uicollectionview not dequeue the cells?

I don't want cells to have to be generated when they come on screen for the first time. 我不希望第一次出现单元格时必须生成单元格。 I also don't want cells that have gone off screen to have to be regenerated when they come back on the screen. 我也不希望离开屏幕的单元格重新出现在屏幕上时必须重新生成。

How can I have all the cells generated on loading the UICollectionView and stay that way as I scroll up and down? 如何在加载UICollectionView时生成所有单元格,并在上下滚动时保持这种状态?

You could manage your own list of cells (pre-create them based on the datasource, create any new ones as the datasource updates, and return the appropriate cell for the indexPath desired instead of dequeuing a cell inside cellForItemAtIndexPath) but as a general rule, that's a bad idea. 您可以管理自己的单元格列表(根据数据源预先创建它们,在数据源更新时创建任何新单元格,并为所需的indexPath返回适当的单元格,而不是使cellForItemAtIndexPath内的单元格出队),但通常是这样,那是个坏主意。 You may have some specific case where cell configuration performance is poor, but the answer is usually "improve cell configuration" and rarely "keep everything in memory". 您可能在某些特定情况下,单元配置性能很差,但是答案通常是“改善单元配置”,而很少“保留所有内容”。

Speculating: If you're thinking of doing this in order to preserve state or cache some information in the cell, that's the wrong place to put it. 推测:如果您正在考虑这样做是为了保留状态或在单元中缓存某些信息,那是放错位置的地方。 The cell is presentation; 单元格是演示文稿; keep that info in the datasource element so that whatever needs to be represented can be applied to whatever cell is being used right now. 将该信息保留在datasource元素中,以便可以将需要表示的内容应用于当前正在使用的任何单元格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM