ios - Updating height of UITableViewCell -


i'm building table shows entry user. 1 of cells shows set of "tags" downloaded server. building set of uilabels , manually adding them view contained in cell. while works, cell not dynamically resize after adding tags. tags overlap cell beneath , can't figure out how manually update height of cell.

in cellforrowatindexpath:

journaltagscell *cell = [tableview dequeuereusablecellwithidentifier:@"journaltagscell" forindexpath:indexpath];   //check if have tags show if(self.journalobject.journalentrytags != nil){     cell.placeholderlabel.hidden = yes;     cell.tagsview = [self updatetagsview:cell.tagsview]; }  return cell; 

the following method creating each tag, laying them out , adding them view:

- (void)updatetagsview:(uiview*)viewtoupdate{      nsarray *items = self.journalobject.journalentrytags;     //clean view first     nsarray *viewstoremove = [viewtoupdate subviews];     (uiview *v in viewstoremove) {         [v removefromsuperview];     }      float x = 10;     float y = 10;      (int = 0; < items.count; i++) {          cgrect textrect = [items[i] boundingrectwithsize:cgsizemake(self.view.frame.size.width - 20, 1000)                                                  options:nsstringdrawinguseslinefragmentorigin                                               attributes:@{nsfontattributename:[uifont tagcopy]}                                                  context:nil];         cgsize size = textrect.size;           if (x+size.width > (self.view.frame.size.width-20)) {             y += size.height + 10;             x = 10;         }           uilabel *lbl = [[uilabel alloc] initwithframe:cgrectmake(x, y, size.width, size.height)];         lbl.userinteractionenabled = yes;         [lbl settext:[nsstring stringwithformat:@" %@ ", items[i]]];         [lbl setfont:[uifont tagcopy]];         [lbl sizetofit];         [lbl settextcolor:[uicolor colorwithred:0.145 green:0.392 blue:0.576 alpha:1.000]];         [lbl setbackgroundcolor:[uicolor colorwithred:0.804 green:0.871 blue:0.914 alpha:1.000]];         lbl.layer.borderwidth = 1;         lbl.layer.bordercolor = [uicolor colorwithred:0.145 green:0.392 blue:0.576 alpha:1.000].cgcolor;         lbl.layer.cornerradius = 5;         [lbl.layer setmaskstobounds:yes];         [viewtoupdate addsubview:lbl];          uitapgesturerecognizer *tapgesture =         [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(userclickedontag:)];         [lbl addgesturerecognizer:tapgesture];          x += size.width + 10;          if (x > (self.view.frame.size.width-20)) {             y += size.height + 10;             x = 10;         }          if (i == items.count-1) {             y+= size.height + 20;         }     }       [viewtoupdate setframe:cgrectmake(0, 0, self.view.frame.size.width, y)]; } 

however, don't know how manually update height cell based on size of view. don't want/need manually calculate height of every single cell, 1 why i'm not using heightforrowatindexpath don't know how update height of 1 cell. can calculate height need cell if necessary i'm setting view frame holds tags, short of having go through every single cell , manually calculate each ones height, i'm stumped.

i think have use heightforrowatindexpath. i'm not sure understand what's happening. or maybe have wrong.. either way, how understand it: total height of "cell" presented. never set "height" of cell, automatically show entire content. heightforrowatindexpath not way tell cell how tall should be, rather how space tableview should reserve particular cell. if pass height short, still present entire cell, next cell start soon. works other way around, if pass bigger number necessary, cells bigger, though cells aren't. it's tableview's representation.


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -