objective c - how load many photos from url in background (asynchronous) -
i have method use load many images scroll view, when images load url scroll view stuck , can't understand how load them in background user not feel it.
this method call few times (8) in "for" cycle.
- (void)loadphotostoleftscroll{ //getting image information json nsmutabledictionary *photodict; photodict = [leftphotoarray lastobject]; //getting photo nsstring *photopath = [photodict objectforkey:@"photos_path"]; nslog(@"photo path:%@",photopath); nsdata * imagedata = [[nsdata alloc] initwithcontentsofurl:[nsurl urlwithstring:photopath]]; uiimage *image = [uiimage imagewithdata:imagedata]; // use image how like, say, button background //calculating hight of next photo uiimageview *leftimage = [leftblockscroll.subviews lastobject]; //allocating photoview uiimageview *photoview = [[uiimageview alloc]initwithframe:cgrectmake(5 , leftimage.frame.origin.y + leftimage.frame.size.height+5, image.size.width/2, image.size.height/2 )]; photoview.userinteractionenabled=yes; [photoview.layer setmaskstobounds:yes]; [photoview.layer setcornerradius:3]; //getting items list nsdictionary *sh_items = [photodict objectforkey:@"items"]; //adding image button uibutton *imageoverbutton = [uibutton buttonwithtype:uibuttontypecustom]; imageoverbutton.frame = cgrectmake(0, 0, photoview.frame.size.width, photoview.frame.size.height); [imageoverbutton addtarget:self action:@selector(leftimagepressed:) forcontrolevents:uicontroleventtouchupinside]; [imageoverbutton settag:[leftphotoarray count]-1]; [photoview addsubview:imageoverbutton]; //adding sh button imageview [self addthe_sh_signs:sh_items to_imageview:photoview]; //subviewing image scrollview [self insert_image:image toimageview:photoview in_scroll:leftblockscroll]; //calclulating position of next imageview in scroll. nextleftphotohight = photoview.frame.size.height + photoview.frame.origin.y + 5; //calculating hight of highest scroll view in both. leftblockscroll.contentsize = cgsizemake(160, [self thesizeofscrollviewhight]); rightblocscroll.contentsize = cgsizemake(160, [self thesizeofscrollviewhight]); isloadindcontant = no; [self.view reloadinputviews]; [leftblockscroll reloadinputviews]; }
please not send me link trying explain how use asynchronous. try explain according method see here. im here question, need ask me.
you have asynchronously in proper way. not think there way around that. subclassed uiimageview object , placed many instances of within cells of talbe (in case within scroll view). subclass objects initialized url , load image asynchronously (with caching image not loaded every time).
this tutorial helped me in beginning: http://www.markj.net/iphone-asynchronous-table-image/
you have adopt scroll view. underlaying principle remains same.
Comments
Post a Comment