ios - UITableviewCell row height shrinking -
i have uitableviewcell
2 labels , switch. when switch value changes state off
remove 1 of labels , when changed on
added view. have used auto layout. when wanted add added lost constraints while removing. here code snippet
- (void)willupdatecell:(sampletableviewcell *)cell{ nsindexpath *indexpath = [self.tableview indexpathforcell:cell]; if ([cell.messageswitch ison]) { cell.messagedescription = [uilabel new]; cell.messagedescription.translatesautoresizingmaskintoconstraints = no; cell.messagedescription.text = self.messages[indexpath.row][@"description"]; cell.messagedescription.numberoflines = 0; cell.messagedescription.linebreakmode = nslinebreakbywordwrapping; [cell.contentview addsubview:cell.messagedescription]; cell.left = [nslayoutconstraint constraintwithitem:cell.messagedescription attribute:nslayoutattributetrailing relatedby:nslayoutrelationequal toitem:cell.messageswitch attribute:nslayoutattributetrailing multiplier:1.0 constant:0]; cell.bottom = [nslayoutconstraint constraintwithitem:cell.messagedescription attribute:nslayoutattributebottom relatedby:nslayoutrelationequal toitem:cell.contentview attribute:nslayoutattributebottom multiplier:1.0 constant:15]; cell.top = [nslayoutconstraint constraintwithitem:cell.messagedescription attribute:nslayoutattributetop relatedby:nslayoutrelationequal toitem:cell.messagetitle attribute:nslayoutattributetop multiplier:1.0 constant:2]; cell.right = [nslayoutconstraint constraintwithitem:cell.messagedescription attribute:nslayoutattributeleading relatedby:nslayoutrelationequal toitem:cell.contentview attribute:nslayoutattributeleading multiplier:1.0 constant:15]; [cell.contentview addconstraints:@[cell.bottom,cell.left,cell.right,cell.top]]; }else{ [cell.messagedescription removefromsuperview]; } [cell updatefont]; [cell.contentview updateconstraints]; [uiview animatewithduration:0.5 animations:^{ [cell.contentview setneedslayout]; }]; }
the issue have shrinking height of row when state of switch changes. spacing still remains after view removed. if tried reload table, tableview behaves weirdly. have attached code here reference. please suggest me can tableview shrink row height when subview removed.
Comments
Post a Comment