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