简体   繁体   English

Swift iOS - collectionView中最佳的单元格数量

[英]Swift iOS - optimal amount of cells in collectionView

I have collectionView in my swift app, each cell is composed of a thumbnail image. 我在我的swift应用程序中有collectionView,每个单元格都由缩略图组成。

Right now I have 100 cells initially, and I paginate results from my backend, so the user can click a next button to get the next 100 images, and I call collectionView.reloadData() so I re-use the initial 100 cells. 现在我最初有100个单元格,并且我从后端分页结果,因此用户可以单击下一个按钮来获取接下来的100个图像,然后调用collectionView.reloadData()以便重新使用最初的100个单元格。

Is there an optimal amount of cells I should have? 我应该有最佳数量的细胞吗? I can instead paginate by each 1000, so I have a 1000 cells, but I'm guessing this could cause problems having so many cells in memory at once? 我可以改为每1000个分页,所以我有一个1000个单元格,但我猜这可能导致在内存中同时存在这么多单元格的问题?

There's no limit at all. 没有任何限制。

"1000" is absolutely nothing. “1000”绝对没有。

Your only consideration here would be, what is a good chunk size to grab depending on your bandwidth . 你唯一需要考虑的是, 根据你的带宽 ,抓取的块大小是多少。

That is to say, you have no issues whatsoever with the collection view . 也就是说,您对集合视图没有任何问题 You just want to pick a good chunk size, so that in terms of networking , from the user's point of view it feels like it is loading smoothly. 你只是想选择一个很好的块大小,所以在网络方面 ,从用户的角度来看,它感觉它是顺利加载。 (Try 2500 to begin with and vary it up and down.) (In really sophisticated apps, you vary that amount dynamically, depending on measurements you make while the app is running, but that is irrelevant here.) (尝试2500开始并上下变化。)(在非常复杂的应用程序中,您可以动态地改变该数量,具体取决于您在应用程序运行时所做的测量,但这与此无关。)

Again you have absolutely no issues, whatsoever, with the collection view . 再次,您对集合视图绝对没有任何问题 Set it to any value you want . 将其设置为您想要的任何值 Set it to 100 million if you feel like it. 如果您愿意,可将其设置为1亿。

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

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