ios - Hiding a UILabel from a UITableViewCell doesn't resize the contentView -


i'm trying create dynamic uitableview cell can expand/collapse user selects cell.

- (void)setupcell:(dynamictableviewcell *)cell atindexpath:(nsindexpath *)indexpath {     cell.label.text = [self.datasource objectatindex:indexpath.row];     cell.secondlabel.text = [self.datasource objectatindex:self.datasource.count - indexpath.row - 1];     if ([self.isvisible[indexpath.row] isequal:@no]) {         cell.secondlabel.hidden = yes;     } else {         cell.secondlabel.hidden = no;     } }   - (nsinteger)numberofsectionsintableview:(uitableview *)tableview {     return 1; }  - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section {     return self.datasource.count; }  - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     dynamictableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier forindexpath:indexpath];     [self setupcell:cell atindexpath:indexpath];      return cell; }  - (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {     dynamictableviewcell *cell = [tableview cellforrowatindexpath:indexpath];     if ([self.isvisible[indexpath.row] isequal: @yes]) {         self.isvisible[indexpath.row] = @no;         cell.secondlabel.hidden = yes;     } else {         self.isvisible[indexpath.row] = @yes;         cell.secondlabel.hidden = no;     } }  - (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath {     static dynamictableviewcell *cell = nil;     static dispatch_once_t oncetoken;      dispatch_once(&oncetoken, ^{         cell = [self.tableview dequeuereusablecellwithidentifier:cellidentifier];     });      [self setupcell:cell atindexpath:indexpath];      return [self calculateheightforconfiguredsizingcell:cell]; }  - (cgfloat)calculateheightforconfiguredsizingcell:(dynamictableviewcell *)sizingcell {     [sizingcell layoutifneeded];      cgsize size = [sizingcell.contentview systemlayoutsizefittingsize:uilayoutfittingcompressedsize];     return size.height; } 

i forked this project , have test code here.

once cell has been sized not change when selecting cell, hides/shows content of cell. i've tried replacing explicit size calculation uitableviewautomaticdimension. tried reloading cell. seems once cell size has been calculated, not change.

any suggestions try appreciated!

in ios development view never collapses if set hidden property true.

instead should use autolayout. assuming view has 2 labels vertically stacked on top of each other, pin first label cells contentview's top, give height constraint, pin second label's top first labels bottom, pin second labels bottom cell's contentview bottom. set height of second label, , save constraint in variable, lets called secondlabelheightconstraint, can collapse , expand cell setting value of secondlabelheightconstraint 0 or ever value like.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -