UICollectionView而不重用单元格 [英] UICollectionView without reusing cells

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

问题描述

很好奇,是否可以在 UICollectionview 上禁用重用功能?
我的单元格数量有限,可能会有所不同,但是单元格的重新初始化可能会有点沉重,最好不要再使用它们。
尝试在没有 dequeueReusableCellWithReuseIdentifier 的情况下初始化单元格

Just curious, is it possible to disable the reuse functionality on UICollectionview? I have a limited amount of cells, which may vary, but the reinitialization of the cell might be a little heavy and I'm better off not reusing them. Trying to initialize the cell without dequeueReusableCellWithReuseIdentifier I get the exception:


NSInternalInconsistencyException,原因:未通过调用-dequeueReusableCellWithReuseIdentifier:forIndexPath来检索collectionView:cellForItemAtIndexPath:返回的视图。

NSInternalInconsistencyException', reason: 'the view returned from collectionView:cellForItemAtIndexPath: was not retrieved by calling -dequeueReusableCellWithReuseIdentifier:forIndexPath.


推荐答案


单元格的重新初始化可能会有点繁琐

the reinitialization of the cell might be a little heavy

重置单元格的内容将比创建一个新单元格更为昂贵-单元格重用的全部目的是通过避免不断创建新单元格的需要来提高性能。

It's unlikely that resetting the contents of a cell will be more expensive than creating a new one -- the whole point of cell reuse is to improve performance by avoiding the need to constantly create new cells.


尝试在不使用dequeueReusableCellWithReuseIdentifier的情况下初始化单元格我得到了例外:

Trying to initialize the cell without dequeueReusableCellWithReuseIdentifier I get the exception:

强烈表明您的问题的答案是。此外,文档说

I'd take that as a strong indication that the answer to your question is no. Further, the documentation says:


...集合视图要求您始终使视图出队,而不是出队

...the collection view requires that you always dequeue views, rather than create them explicitly in your code.

再次,

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

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