Search code examples
iosobjective-cuitableviewios-autolayoutuitableviewautomaticdimension

How to change height Constraint of UIView in UitableviewCell when using UITableViewAutomaticDimension


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;
}

Solution

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

     cell.viewHeightCon.constant = // value
    

    and before return cell add

     cell.layoutIfNeeded()