5

enter image description here

I have a UIView in the UITableViewCell , which needs to change its height when user taps on "less/more" button

My code is

 - (CGFloat)tableView:(UITableView *)tableView       estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewAutomaticDimension;
}
Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87
SThakur
  • 262
  • 4
  • 16
  • 1
    take a look here, and next time try to research a bit before asking a question (there are many question about expandable cells): https://stackoverflow.com/a/47963680/2912282 – Milan Nosáľ Jan 23 '18 at 12:26
  • Possible duplicate of [Programmatically creating an expanding UItableViewCell](https://stackoverflow.com/questions/47963568/programmatically-creating-an-expanding-uitableviewcell) – Milan Nosáľ Jan 23 '18 at 12:28

1 Answers1

6

Hook items height constraint as IBOutlet and change it in cellForRow like this

 cell.viewHeightCon.constant = // value

and before return cell add

 cell.layoutIfNeeded()
Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87
  • Can you plz tell me how to set the priorities of constraints to fix it? – SThakur Jan 23 '18 at 12:26
  • no need to fix priorities this will stretch automatically , see design your cell prototype or xib in expanded state and hook height of ones you want to change in runtime as iboutlets – Shehata Gamal Jan 23 '18 at 12:29
  • I did the same as you suggested & set the clipsTobounds property yes, which resolved my issue.. – SThakur Jan 23 '18 at 13:34