1 iOS multi-image download, download images in cell, Cache optimizer. 2 3 (App.icon is the image address)4 5 //Take the picture out of the memory cache first6UIImage *image =Self.images[app.icon];7 if(image) {//There are pictures in memory8Cell.imageView.image =image;9}Else{//no pictures in memoryTen //Get library/caches folder OneNSString *cachespath =[Nssearchpathfordirectoriesindomains (Nscachesdirectory, Nsuserdomainmask, YES) firstobject]; A //Get file name -NSString *filename =[App.icon lastpathcomponent]; - //calculate the full path of a file theNSString *file =[Cachespath stringbyappendingpathcomponent:filename]; - //loading the sandbox's file data -NSData *data =[NSData Datawithcontentsoffile:file]; - + if(data) {//Direct use of pictures in sandbox -UIImage *image =[UIImage Imagewithdata:data]; +Cell.imageView.image =image; A //Save in Dictionary atSelf.images[app.icon] =image; -}Else{//Download Image -[Self.queue addoperationwithblock:^{ - //download pictures, multithreading -NSData *data =[NSData Datawithcontentsofurl:[nsurl URLWithString:app.icon]; -UIImage *image =[UIImage Imagewithdata:data]; in -[Nsthread Sleepfortimeinterval:1.0]; to + //back to main thread display picture -[[Nsoperationqueue Mainqueue] addoperationwithblock:^{ theCell.imageView.image =image; * }]; $ Panax Notoginseng //Save in Dictionary -Self.images[app.icon] =image; the //writing picture file data into a sandbox + [Data writetofile:file atomically:yes]; A }]; the}
iOS multi-image download