从TableViewCell中的URL预加载图像 [英] Preloading images from URL in TableViewCell

查看:169
本文介绍了从TableViewCell中的URL预加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为iPhone开发一个简单的rss阅读器.供稿( http://feeds.feedburner.com/foksuk/gLTI )包含参考到要在TableView中显示的图像. 据我所知,默认情况下,iPhone仅尝试在需要时加载图像:它将仅加载显示行的图像.仅当用户向下滚动时,它才会开始加载需要显示的内容.正确的? 现在,由于图像是从网络上下载的(它们并不太大,但仍然很大),因此TableView的滚动变得混乱.这是在模拟器中,因此在设备本身上只会更糟. 幸运的是,此特定的提要仅列出了博客的最新12个条目.因此,我想我应该能够首先下载所有图像的缓存,以便可以从内存而不是从URL加载它们. 这里合适的方法是什么?

I'm making a simple rss reader for the iPhone. The feed (http://feeds.feedburner.com/foksuk/gLTI) contains a reference to images that I want to show in my TableView. By default, as far as I understand, the iPhone only tries to load images when they are needed: it will only load the images for the rows that are displayed. Only when the user scrolls down, it will start loading the ones that need to be displayed. Right? Now, since the images are downloaded from the web (they are not too large, but still), the scrolling of my TableView is stuttering. This is in the emulator, so on the device itself it will only be worse. Luckily, this specific feed only lists the latest 12 entries of the blog. So I guess I should be able to first download an cache all the images, so they can be loaded from the memory, rather than from the URL. What is the proper approach here?

推荐答案

我遇到了同样的问题,即TableView必须先下载每个图像,然后才能显示该单元格.就像您说的那样,它会导致滚动速度大大降低.您需要做的是在后台下载图像,然后在完成下载后将其插入单元格中.这是应用商店应用程序执行此操作的方式.

I had the same problem, where my TableView would have to download each image before it displayed the cell. Like you say, it causes a big slowdown in the scrolling speed. What you need to do is download the images in the background and then insert them into the cell when they're finished downloading. This is how the app store app does it.

您需要了解的所有信息,包括可以立即使用的类文件:

This post has all you need to know, including a class file you can use straight away:

http://www.markj.net/iphone-asynchronous-table-图片/

这篇关于从TableViewCell中的URL预加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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