How to fetch images for every UiTableViewCell efficently?

邮差的信 提交于 2019-12-13 04:01:13

问题


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

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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/5715850/how-to-fetch-images-for-every-uitableviewcell-efficently

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!