iOS multi-image download

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.