动态加载 UICollectionView 数据源 [英] Loading UICollectionView data source dynamically

查看:26
本文介绍了动态加载 UICollectionView 数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在加载 UICollectionView 时遇到问题.数据源是一个数组.该数组可能最多包含 10k 个元素.转换完成后,在数组中创建对象需要花费大量时间.

I have an issue with loading UICollectionView. Data source is an array. The array might consist of up to 10k elements. After transitioning is done, it is taking a lot of time to create objects in the array.

我不确定这是否是最初使用 n (<< 10k) 个元素加载数组并在滚动时添加对象的正确方法.

I am not sure if it is the right way to load the array initially with n (<< 10k) elements and add the objects while scrolling.

任何建议都会很有帮助.谢谢

Any advice would really be helpful. Thanks

推荐答案

如果你使用的是 Core Data,你可以批量获取.如果您不使用 CD,那么您需要实现自己的机制来进行批处理.加载(并等待!)加载任意数量的对象总是一个坏主意.所以建议是:在后台队列中批量加载数据.然后每个 x(可能是 1)个加载的对象,将它们发布回主线程,以便您的 viewController 可以重新加载或在 collectionView 中添加必要的单元格.

If you are using Core Data, you can fetch in batches. If you are not using CD, then you need to implement your own mechanism to do the batching. Loading (and waiting!) for any number of objects to load is always a bad idea. So the advice is: load the data in batches, on a background queue. Then every x (could be 1) loaded objects, post them back on the main thread so that your viewController can then reload or add the necessary cells in the collectionView.

这篇关于动态加载 UICollectionView 数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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