将图像从URL加载到表视图单元格中的图像视图的更快方法 [英] Faster way to load image from an URL to image view in table view cell

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

问题描述

我用它来加载URL到图像视图

I am using this to load URL to image view

let url = NSURL(string: URL)
let data = NSData(contentsOfURL: url!)
self.releasephoto.image  = UIImage(data: data!)

但是当表视图单元格中有10个项目有不同的图像时,滚动变慢并挂起

But when there is 10 items in table view cell with different images, scrolling gets slower and hangs

我加载大小为40 X 40的图像

I load images with the size of 40 X 40

我想知道是否有更好的方法来加载URL图像?

I wonder if there is a better way to load URL images ?

推荐答案

我建议使用 SDWebImage

安装完成后,你需要为Swift创建一个桥接头并包括这一行:

After installing it you'll need to make a bridging header for Swift and include this line:

#import "UIImageView+WebCache.h"

然后你需要在你的cellForRowAtIndexPath函数中做的就是:

Then all you need to do in your cellForRowAtIndexPath function is this:

let url = NSURL(string: URL)
self.releasephoto.sd_setImageWithURL(url)

这个库的优点在于它会自动缓存图像,因此只下载一次。

The nice thing about this library is that it automatically caches the image so it's only downloaded once.

这篇关于将图像从URL加载到表视图单元格中的图像视图的更快方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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