当我使用url将UIImage设置为NSData时,加载需要一段时间。 [英] Loading takes a while when i set UIImage to a NSData with a url.

查看:154
本文介绍了当我使用url将UIImage设置为NSData时,加载需要一段时间。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

NSData *imageUrl = [NSData dataWithContentsOfURL:[NSURL URLWithString:[[self.content objectAtIndex:indexPath.row] valueForKey:@"imageUrl"] ]];
cell.thumbnailImageView.image=[UIImage imageWithData:imageUrl];

这是我使用 imageUrl 加载的方式它们进入 UIImage 但加载需要一段时间,程序似乎崩溃或进入无限循环。

this is how i use imageUrl to load them into UIImage but it takes a while to load and the program seems like it crashed or entered to an infinite loop.

如何使用url更快地制作 UIImage 的内容?

How can i make the content of UIImage with url but faster?

推荐答案

使用 sdwebimage 并从此处<下载库文件/ a>

use sdwebimage and down load the library file from here

您遵循的几个步骤

添加 sdwebimage

在你的.h文件中

#import "UIImageView+WebCache.h"

.m文件中的

in your .m file

调用 cellforRowAtIndexPath中的单行

[cell.thumbnailImageView setImageWithURL:[NSURL URLWithString:[[self.content objectAtIndex:indexPath.row] valueForKey:@"imageUrl"]]
                                     placeholderImage:[UIImage imageNamed:@"placeholder.png"]];

这篇关于当我使用url将UIImage设置为NSData时,加载需要一段时间。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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