开发者

How to fetch images for every UiTableViewCell efficently?

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]; 

Ho开发者_运维问答w 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.


you can implement lazy loading try this out 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 good luck


Create class to download the Images. After downloading the Image you can Implement a delegate method. In the Delegate method Reload the cell with corresponding images.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜