sd_webimage-03-multi-threaded + download task into non-main thread execution

Source: Internet
Author: User

1 //2 //UIIMAGEVIEW+WEBCACHE.M3 //02-sdwebimage4 //5 //Created by Mac on 16/4/20.6 //copyright©2016 Year Mac. All rights reserved.7 //8 9 #import "uiimageview+webcache.h"Ten  One @implementationUiimageview (Webcache) A  - /** - * Note: There is a task should open multi-threading, the download into the non-main thread, the loading UI must be put into the main thread the  */ -  -- (void) Setimagewithurl: (Nsurl *) URL { -      + //NSData *data = [NSData Datawithcontentsofurl:url]; - //     + //UIImage *image = [UIImage imagewithdata:data]; A //     at //self.image = image; -      -     //1. Turn on multithreading - [Self performselectorinbackground: @selector (downloadimage:) Withobject:url]; - } -  in- (void) Downloadimage: (Nsurl *) URL { -      toNSData *data =[NSData Datawithcontentsofurl:url]; +      -UIImage *image =[UIImage Imagewithdata:data]; the      *     //2. All UI-related operations should be performed in the main thread $ [Self performselectoronmainthread: @selector (setimage:) withobject:image Waituntildone:no];Panax Notoginseng } -  the @end

sd_webimage-03-multi-threaded + download task into non-main thread execution

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.