如何有效地将图像从服务器加载到tableView? [英] How to load images from server to tableView efficiently?

查看:51
本文介绍了如何有效地将图像从服务器加载到tableView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表格视图,其中所有单元格都有UITableViewCellStyleSubtitle,所有单元格的图像都是从服务器获取的.

I have a table view with all cells having the UITableViewCellStyleSubtitle, the images of all the cells are got from the server.

但是,这些图像不会经常更改.

However, those images are not changed frequently.

有人可以告诉我如何改善用户体验吗?每次用户向下滚动表格时,似乎它都已联机以再次检查和下载图像.

Someone can show me how to improve the user experience? Each time, user scroll down the table, it seems that it goes online to check and download images again.

或者至少,请告诉我一些可以实现目标的选项.

Or at least, show me some options that are available to achieve the goal.

谢谢

推荐答案

Three20 库具有一个ImageView子类,该子类可以接受指向远程图像的URL,并使用出色的TTURLRequest/Caching机制来获取图像.它维护内存中和磁盘上的缓存,并且仅在未缓存或已过期的图像时才下载图像.您可以配置默认的缓存过期时间,也可以使用HTTP响应中的值.如果使用TTTableViewController子类和适当的TTTableItem子类,则将免费获得适当的图像下载行为.但是,没有必要使用每三个组件来做您需要的事情.如果要集成到现有代码中,则可以创建自己的UITableViewCell子类,该子类使用TTImageView而不是标准UIImageView.然后,在单元格配置方法中,您可以设置默认的占位符图像和要加载的URL,其余的工作将由它来完成.作为性能优化,您还应该在表视图控制器中实现UIScrollView委托方法,以在滚动过程中挂起TTURLRequestQueue(请看一下TTTableViewController看看这样做是如何完成的.)

The Three20 library has an ImageView subclass that accepts a URL to your remote image and uses the excellent TTURLRequest/Caching mechanism to fetch images. It maintains an in-memory and on-disk cache and will only download images if they are not cached or have expired. You can configure the default cache-expiration time or use a value from your HTTP response. If you use the TTTableViewController subclass and the appropriate TTTableItem subclass, you will get the appropriate image downloading behavior for free. However, it is not necessary to use every three component to do what you need. If you're integrating into existing code, you could create your own UITableViewCell subclass that uses a TTImageView instead of the standard UIImageView. Then, in your cell configuration methods, you can set a default placeholder image and a URL to load and it will pretty much take care of the rest. As a performance optimization, you should also implement the UIScrollView delegate methods in your tableview controller to suspend the TTURLRequestQueue during scrolling (take a look at the TTTableViewController to see how this is done).

这篇关于如何有效地将图像从服务器加载到tableView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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