ios - NSString value overlays others when displayed in UITextView parse.com -


if change titletextview.backgroundcolor = [uicolor clearcolor] other colour displays need, if leave is, overlays [object objectforkey:@"imagetitle"] values.

has encountered such issue? suggestions?

here doing right now.

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath object:(pfobject *)object { static nsstring *cellidentifier = @"cell";  nsuinteger index = [self indexforobjectatindexpath:indexpath];  if (indexpath.row % 2 == 0) {     // header     return [self detailphotocellforrowatindexpath:indexpath]; } else {     // photo     photoviewcell *cell = (photoviewcell *)[tableview dequeuereusablecellwithidentifier:cellidentifier];      if (cell == nil) {         cell = [[photoviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier];      }      cell.photobutton.tag = index;     cell.imageview.image = [uiimage imagenamed:@"placeholderphoto.png"];      if (object) {           uitextview * titletextview = [[uitextview alloc]initwithframe:cgrectmake(0, cell.imageview.bounds.size.width/2, cell.imageview.bounds.size.width, cell.imageview.bounds.size.width)];          cell.imageview.file = [object objectforkey:kpapphotopicturekey];            titletextview.backgroundcolor = [uicolor clearcolor];         titletextview.text = [object objectforkey:@"imagetitle"];         titletextview.font = [uifont fontwithname:@"arial" size:30];         titletextview.textcolor = [uicolor redcolor];         [cell.contentview addsubview: titletextview];           static nsstring *cellidentifier = @"footercell";          photofooterview *footerview = [self.tableview dequeuereusablecellwithidentifier:cellidentifier];          if (!footerview) {             footerview = [[photofooterview alloc] initwithframe:cgrectmake( 0.0f, cell.imageview.frame.size.height, self.view.bounds.size.width, 44.0f) buttons:photofooterbuttonsdefault];             footerview.delegate = self;             }         pfobject *object = [self objectatindexpath:indexpath];         footerview.photo = object;         footerview.tag = index;         [footerview.likebutton settag:index];          nsdictionary *attributesforphoto = [[appcache sharedcache] attributesforphoto:object];          if (attributesforphoto) {             [footerview setlikestatus:[[appcache sharedcache] isphotolikedbycurrentuser:object]];             [footerview.likebutton settitle:[[[appcache sharedcache] likecountforphoto:object] description] forstate:uicontrolstatenormal];             [footerview.commentbutton settitle:[[[appcache sharedcache] commentcountforphoto:object] description] forstate:uicontrolstatenormal];              if (footerview.likebutton.alpha < 1.0f || footerview.commentbutton.alpha < 1.0f) {                 [uiview animatewithduration:0.200f animations:^{                     footerview.likebutton.alpha = 1.0f;                     footerview.commentbutton.alpha = 1.0f;                 }];             }         } else {             footerview.likebutton.alpha = 0.0f;             footerview.commentbutton.alpha = 0.0f;              @synchronized(self) {                 // check if can update cache                 nsnumber *outstandingsectionheaderquerystatus = [self.outstandingsectionheaderqueries objectforkey:@(index)];                 if (!outstandingsectionheaderquerystatus) {                     pfquery *query = [aaputility queryforactivitiesonphoto:object cachepolicy:kpfcachepolicynetworkonly];                     [query findobjectsinbackgroundwithblock:^(nsarray *objects, nserror *error) {                         @synchronized(self) {                             [self.outstandingsectionheaderqueries removeobjectforkey:@(index)];                              if (error) {                                 return;                             }                              nsmutablearray *likers = [nsmutablearray array];                             nsmutablearray *commenters = [nsmutablearray array];                              bool islikedbycurrentuser = no;                              (pfobject *activity in objects) {                                 if ([[activity objectforkey:kpapactivitytypekey] isequaltostring:kpapactivitytypelike] && [activity objectforkey:kpapactivityfromuserkey]) {                                     [likers addobject:[activity objectforkey:kpapactivityfromuserkey]];                                 } else if ([[activity objectforkey:kpapactivitytypekey] isequaltostring:kpapactivitytypecomment] && [activity objectforkey:kpapactivityfromuserkey]) {                                     [commenters addobject:[activity objectforkey:kpapactivityfromuserkey]];                                 }                                  if ([[[activity objectforkey:kpapactivityfromuserkey] objectid] isequaltostring:[[pfuser currentuser] objectid]]) {                                     if ([[activity objectforkey:kpapactivitytypekey] isequaltostring:kpapactivitytypelike]) {                                         islikedbycurrentuser = yes;                                     }                                 }                             }                              [[appcache sharedcache] setattributesforphoto:object likers:likers commenters:commenters likedbycurrentuser:islikedbycurrentuser];                              if (footerview.tag != index) {                                 return;                             }                              [footerview setlikestatus:[[appcache sharedcache] isphotolikedbycurrentuser:object]];                             [footerview.likebutton settitle:[[[appcache sharedcache] likecountforphoto:object] description] forstate:uicontrolstatenormal];                             [footerview.commentbutton settitle:[[[appcache sharedcache] commentcountforphoto:object] description] forstate:uicontrolstatenormal];                              if (footerview.likebutton.alpha < 1.0f || footerview.commentbutton.alpha < 1.0f) {                                 [uiview animatewithduration:0.200f animations:^{                                     footerview.likebutton.alpha = 1.0f;                                     footerview.commentbutton.alpha = 1.0f;                                 }];                             }                         }                     }];                 }             }         }          [cell addsubview:footerview];          // pfqtvc take care of asynchronously downloading files, load them when tableview not moving. if data there, let's load right away.         if ([cell.imageview.file isdataavailable]) {             [cell.imageview loadinbackground];         }       }     return cell;     } } 

thanks in advance

the problem uitableview cells reused. when cell scrolls off edge of table, "new" cell replaces on other side same object (providing dramatic savings in view creation , destruction).

dequeuereusablecellwithidentifier: returns 1 of cells, of time reused scrolled-away position. cellforrowatindexpath adds text view every time, means of time piling text view upon text view. clear color background allows notice mistake.

the fix build text view conditionally, if cell doesn't have 1 already, this...

    // existing code here      uitextview *titletextview = (uitextview *)[cell viewwithtag:99];     // condition guards against building text view when have 1     if (!textview) {         titletextview = [[uitextview alloc]initwithframe: // , on         // can find later in viewwithtag line above         titletextview.tag = 99;         // code build text view here, not line         // sets text.  unconditionally every cell         [cell.contentview addsubview: titletextview];     }     // part of view varies cell, unconditionally...     titletextview.text = [object objectforkey:@"imagetitle"];      // existing code here 

as aside, remainder of cellforrowatindexpath method long , non-standard, 2 warning signs of troubles ahead. i'm puzzled second call dequeue "footerview".

and ill-advised launch asynch calls in method without first checking if you've fetched data. remember, method gets called on , on rapidly user scrolls on same cells. same reason build single text view per cell, need guard insure single request (or fewer) per cell.

step 1 fix move of model-related code out of datasource method. have model cache results, , return completion right away if result has been fetched.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -