如何有效地为每个UiTableViewCell获取图像? [英] How to fetch images for every UiTableViewCell efficently?

查看:95
本文介绍了如何有效地为每个UiTableViewCell获取图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用代表中从互联网接收并解析JSON。在JSON中,存在必须在表格单元格中显示的图像的链接(每个单元格1个图像)。
如果我在cellForRowAtIndexPath方法中获取图像,则加载整个视图需要相当长的时间。我在cellForRowAtIndexPath中使用此代码:

I receive and parse JSON from the internet in my app delegate. In JSON there are links to images that must be displayed in table cells (1 image per cell). If i fetch images in cellForRowAtIndexPath method, it takes quite some time to load the whole view. I use this code in cellForRowAtIndexPath:

NSURL *url = [NSURL URLWithString:imageUrl];  
NSData *data = [NSData dataWithContentsOfURL:url];  
cell.imageView.image = [UIImage imageWithData:data]; 

如何在不降低应用程序启动速度的情况下获取这些图像(我应该在哪里放置代码)?
我读了一些关于NSOperation的事情,这是正确的方法吗?

How should i fetch these images without slowing down application launch (where should i put my code)? I read a few things about NSOperation, is this the right way to go?

Tnx。

推荐答案

你可以实现延迟加载
试试这个
http://kshitizghimire.com.np/lazy- loading-custom-uitableviewcell /

或者你可以检查苹果的例子

or you can check apple's example

http://developer.apple。 com / library / ios /#samplecode / LazyTableImages / Introduction / Intro.html#// apple_ref / doc / uid / DTS40009394
祝你好运

http://developer.apple.com/library/ios/#samplecode/LazyTableImages/Introduction/Intro.html#//apple_ref/doc/uid/DTS40009394 good luck

这篇关于如何有效地为每个UiTableViewCell获取图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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