ios - how to avoid delay when adding more than one button to scrollview in iPhone? -
i need add more 1 button (its depend upon array count) uiscrollview.now using following code.this code working more time ( delay adding button) taking function.please me..
   (int i=0; i< [imagearray count]; i++) {     nsurl *url = [nsurl urlwithstring:[[imgarray objectatindex:i]objectforkey:@"url"]];     uiimage *img = [uiimage imagewithdata:[nsdata datawithcontentsofurl:url]];     uibutton *button1 = [uibutton buttonwithtype:uibuttontypecustom];     button1.frame = cgrectmake(xp, 0, 75, 75);     [button1 setimage:img forstate:uicontrolstatenormal];     [button1 addtarget:self action:@selector(buttonclicked:) forcontrolevents:uicontroleventtouchupinside];     button1.layer.bordercolor = [uicolor whitecolor].cgcolor;     button1.layer.borderwidth = 2.0;     [mscrollview addsubview:button1];     xp += button1.frame.size.width+15; } 
because loading image server blocks main thread till image load completely. try loading image in different thread
below example shows how load image on diffrent thread
add button object , url in array (this can written inside loop)
 nsmutablearray *array = [[nsmutablearray alloc] initwithcapacity:0]; [array addobject:cell.businesslogoimageview]; [array addobject:@"your url"]; [nsthread detachnewthreadselector:@selector(loadimage:) totarget:self withobject:array]; [array release]; array = nil; now implement loadimage
-(void)loadimage:(nsarray *)objectarray  {     uiimageview *tempimageview = (uiimageview *)[objectarray objectatindex:0];     tempimageview.image=[uiimage imagewithdata:[nsdata datawithcontentsofurl:[nsurl urlwithstring:[objectarray objectatindex:1]]]];   } 
Comments
Post a Comment