问题
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?
回答1:
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-image/
来源:https://stackoverflow.com/questions/932859/preloading-images-from-url-in-tableviewcell