How to change height Constraint of UIView in Uitab

2019-08-05 01:21发布

问题:

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

回答1:

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

 cell.viewHeightCon.constant = // value

and before return cell add

 cell.layoutIfNeeded()