uiimageview - Asynchronous images loading again and again in the Uitableview cells -


having trouble asynchronous images don't know why having weird problem. applying asynchronous images load technique images not freezing once loaded on scrolling again loading.

    - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath{     static nsstring *cellidentifier = @"cell";     uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier];     if (cell == nil) {         cell=[self getcellcontentview:cellidentifier];     }     [cell setbackgroundcolor:[uicolor redcolor]];     nslog(@"%i",[discussionarray count]);     nsdictionary *dict=[discussionarray objectatindex:indexpath.row];     uilabel *textlabel1 = (uilabel *)[cell viewwithtag:1];     uilabel *textlabel2 = (uilabel *)[cell viewwithtag:2];     uilabel *textlabel3 = (uilabel *)[cell viewwithtag:3];     uiimageview *avatarimage = (uiimageview *)[cell viewwithtag:4];     uiimageview *new_oldimage = (uiimageview *)[cell viewwithtag:5];     uiimageview *avatarimage_cover = (uiimageview *)[cell viewwithtag:6];      textlabel1.text =[dict objectforkey:@"user"];     textlabel2.text =[dict objectforkey:@"date"];     textlabel3.text =[dict objectforkey:@"text"];      nsstring *photostrn=[dict objectforkey:@"photo"];     avatarimage.image = nil;     dispatch_async(dispatch_get_global_queue(0,0), ^{         nsstring *u=[nsstring stringwithformat:@"http://%@",photostrn];         nsurl *imageurl=[nsurl urlwithstring:u];         nsdata *imagedata = [nsdata datawithcontentsofurl:imageurl];         dispatch_sync(dispatch_get_main_queue(), ^{             uiimage *dpimage = [uiimage imagewithdata:imagedata];             if (dpimage==nil)             {                 dpimage = [uiimage imagenamed:@"profileimage.png"];             }               [uiview animatewithduration:5.0 animations:^{                 avatarimage.alpha = 1.0;             }];             avatarimage.image = dpimage;          });      });      avatarimage_cover.image = [uiimage imagenamed:@"avtrcover.png"];      nsstring *new=[dict objectforkey:@"new"];     if ([new isequaltostring:@"0"])     {         new_oldimage.image = [uiimage imagenamed:@"old_message.png"];     }     else     {         new_oldimage.image = [uiimage imagenamed:@"new_message.png"];     }      textlabel3.numberoflines = 0;     nsstring *detailtext = [[discussionarray objectatindex:indexpath.row] objectforkey:@"text"];     cgsize textsize = [detailtext sizewithfont:[uifont boldsystemfontofsize:13] constrainedtosize:cgsizemake(240, maxfloat) linebreakmode:uilinebreakmodewordwrap];     textlabel3.frame = cgrectmake(70, 53, 240, textsize.height+detailtextoffset );     return cell;   } 

you setting avatarimage.image nil each time cell configured. call loading code regardless what. thus, not surprising keep reloading image.

instead, should maintain mutable array of downloaded images. file urls images somewhere in documents folder. if image exists use it, if not download it.

if (imagearray[indexpath.row]) {   // use image populate image view } else {   // fetch async server } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -