简体   繁体   English

预加载tableView单元格并防止重新加载

[英]Preload tableView cells and prevent reloading

I already found entries with that topic on this page and also a website that provides a tutorial for that problem. 我已经在此页面上找到了与该主题相关的条目,还有一个提供有关该问题的教程的网站。 But nothing worked very well. 但是没有一件事情做得很好。

The tutorial sad I should double the height of my tableView so cells loaded earlier, but with a higher tableView I never reached the last cells. 不幸的是,本教程我应该将tableView的高度加倍,以便较早地加载单元格,但是在tableView较高的情况下,我从未到达最后一个单元格。

My problem is, I use a tableView to display my apps mainpage. 我的问题是,我使用tableView来显示我的应用程序主页。 This mainPage shows every time a topic and if its necessary for that topic it shows for example a cell with a map, one with pictures and sometimes not. 该mainPage每次都会显示一个主题,并且如果需要该主题,则会显示一个带有地图的单元格,一个带有图片的单元格,有时没有。 Problem now, if I trying to scroll to my view its always lagging because it loads a map or this pictures. 现在出现问题,如果我尝试滚动到视图,则它总是滞后,因为它会加载地图或这张图片。 And scrolling back again because the loaded cells already deleted. 然后再次滚动,因为加载的单元格已被删除。 I used a tableView because of the possibility to switch celltypes(mapCell, pictureCell, textCell) on and off. 我使用tableView是因为可以打开和关闭单元格类型(mapCell,pictureCell,textCell)。

I understand this feature, because of memory issues but in my case its not that much and it would be better if all my cells be preloaded and stay in memory until I change the topic. 我了解此功能是因为内存问题,但就我而言,并不是那么多,最好将所有单元格都预加载并保留在内存中,直到更改主题。

Is there a swifty way to told my tableView to have this behavior? 有没有一种快速的方法告诉我的tableView出现这种现象?

Thanks a lot and nice greetings 非常感谢和问候

I would suggest a different approach. 我建议使用另一种方法。 Set up your table view controller to install placeholder images in your cells, trigger an async download that you cache to disk, and then update the cell with it's downloaded content if it's still visible when the download is finished. 设置表视图控制器,以在单元格中安装占位符图像,触发一个异步下载并缓存到磁盘,然后在下载完成后仍然可见的情况下,用下载的内容更新单元格。

There are various third party frameworks that do all this housekeeping for you. 有各种第三方框架可以为您完成所有这些整理工作。

Declare a cell array. 声明一个单元格数组。

Follow these steps whenever change in your topic. 每当您的主题更改时,请按照下列步骤操作。

  1. Clear you array 清除阵列

  2. Create and configure all cells add to your array. 创建并配置所有添加到阵列的单元。

  3. Return these cells to datasource methods using row index. 使用行索引将这些单元格返回到数据源方法。 Don't use tableview dequeue method here. 在此不要使用tableview出队方法。

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

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