ios - UITableView not populating cell completely until moved off screen -
i using parse populate cells in tableview. each cell contains username, user's picture, , actual post content. when run app, username , post content loaded each cell. picture not loaded until cell moved off screen , moved back. here code involving query:
-(void)retrievefromparse { pfquery *retrieveposts = [pfquery querywithclassname:@"posts"]; [retrieveposts orderbydescending:@"createdat"]; retrieveposts.cachepolicy = kpfcachepolicycachethennetwork; [retrieveposts findobjectsinbackgroundwithblock:^(nsarray *objects, nserror *error) { if (!error) { postsarray = [[nsarray alloc] initwitharray:objects]; dispatch_async(dispatch_get_main_queue(), ^{ [self.tableview reloaddata]; }); } dispatch_async(dispatch_get_main_queue(), ^{ [self.refreshcontrol endrefreshing]; }); }]; }
here code tableview:
-(uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { postcell = [tableview dequeuereusablecellwithidentifier:@"postcellone"]; if (postcell == nil ) { postcell = [[posttableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:@"postcellone"]; } postcell.backgroundcolor = [uicolor blackcolor]; postcell.postername.textcolor = [uicolor whitecolor]; postcell.postcontent.textcolor = [uicolor whitecolor]; pfobject *postobject = [postsarray objectatindex:indexpath.row]; postcell.postername.text = [postobject objectforkey:@"postername"]; postcell.postcontent.text = [postobject objectforkey:@"postcontent"]; uiactivityindicatorview *spinner = [[uiactivityindicatorview alloc]initwithframe:postcell.posterimage.frame]; [postcell.posterimage addsubview:spinner]; spinner.color = [uicolor whitecolor]; [spinner startanimating]; imagefile = [postobject objectforkey:@"posterpicture"]; [imagefile getdatainbackgroundwithblock:^(nsdata *data, nserror *error) { if (!error) { dispatch_async(dispatch_get_main_queue(), ^{ [spinner removefromsuperview]; postcell.posterimage.image = [uiimage imagewithdata:data]; [tableview reloadinputviews]; }); } else { dispatch_async(dispatch_get_main_queue(), ^{ [spinner removefromsuperview]; }); } }]; return postcell; }
i using parse populate cells in tableview. each cell contains username, user's picture, , actual post content. when run app, username , post content loaded each cell. picture not loaded until cell moved off screen , moved back. here code involving query:
-(void)retrievefromparse { pfquery *retrieveposts = [pfquery querywithclassname:@"posts"]; [retrieveposts orderbydescending:@"createdat"]; retrieveposts.cachepolicy = kpfcachepolicycachethennetwork; [retrieveposts findobjectsinbackgroundwithblock:^(nsarray *objects, nserror *error) { if (!error) { postsarray = [[nsarray alloc] initwitharray:objects]; dispatch_async(dispatch_get_main_queue(), ^{ [self.tableview reloaddata]; }); } dispatch_async(dispatch_get_main_queue(), ^{ [self.refreshcontrol endrefreshing]; }); }]; }
here code tableview:
-(void)imagefromimagefile:(pffile *)imagefile forcell:(posttableviewcell *)cell { posttableviewcell *workingcell = cell; uiactivityindicatorview *spinner = [[uiactivityindicatorview alloc]initwithframe:postcell.posterimage.frame]; [workingcell.posterimage addsubview:spinner]; spinner.color = [uicolor whitecolor]; [spinner startanimating]; [imagefile getdatainbackgroundwithblock:^(nsdata *data, nserror *error) { if (!error) { if(workingcell == cell){ dispatch_async(dispatch_get_main_queue(), ^{ [spinner removefromsuperview]; workingcell.posterimage.image = [uiimage imagewithdata:data]; [workingcell setneedslayout]; }); }else{ dispatch_async(dispatch_get_main_queue(), ^{ [spinner removefromsuperview]; }); } } }]; } -(uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { postcell = [tableview dequeuereusablecellwithidentifier:@"postcellone"]; if (postcell == nil ) { postcell = [[posttableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:@"postcellone"]; } postcell.backgroundcolor = [uicolor blackcolor]; postcell.postername.textcolor = [uicolor whitecolor]; postcell.postcontent.textcolor = [uicolor whitecolor]; pfobject *postobject = [postsarray objectatindex:indexpath.row]; postcell.postername.text = [postobject objectforkey:@"postername"]; postcell.postcontent.text = [postobject objectforkey:@"postcontent"]; imagefile = [postobject objectforkey:@"posterpicture"]; cell.posterimage.image = nil; [self imagefromimagefile:imagefile forcell:cell]; return postcell; }
Comments
Post a Comment