ios - Asynchronously set images in tableview -


i have tableview using custom cells. setting grabbing image url in cellforrowatindexpath method

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     static nsstring *simpletableidentifier = @"simpletablecell";      simpletablecell *cell = (simpletablecell *)[tableview dequeuereusablecellwithidentifier:simpletableidentifier];     if (cell == nil)     {         nsarray *nib = [[nsbundle mainbundle] loadnibnamed:@"simpletablecell" owner:self options:nil];         cell = [nib objectatindex:0];     }      nsdictionary *dictobject = [places objectatindex:indexpath.row];     cell.namelabel.text  = [dictobject valueforkey:@"placetitle"];      nsurl *url = [nsurl urlwithstring:@"http://images1.fanpop.com/images/image_uploads/mario-kart-wii-items-mario-kart-1116309_600_600.jpg"];     nsdata *data = [nsdata datawithcontentsofurl:url];     uiimage *image = [uiimage imagewithdata:data];     cell.thumbnailimageview.image = image;      return cell; } 

but making tableview scroll laggy. once removed image fetch, scrolled fine, know problem.

my question is: how can asynchronously fetch image , set in cell? there easy way this? thanks!

step 1: have cache containing images. either in memory, better on disk.

step 2: when need image, call method either returns image cache, or returns default image , starts download.

step 3: when download finishes, add image cache. find out rows need image. reload rows reload image.

the download should done asynchronously using gcd. recommend add download code separate, reusable method can handle download errors. if don't now, later.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

spring cloud - How to configure SpringCloud Eureka instance to point to https on non standard port -

javascript - Bootstrap Popover: iOS Safari strange behaviour -