I am trying to use AutoLayout to configure the subviews in my table view cells and in the ideal case would like the table view cell to be just as high as necessary to contai
Now that you've uploaded the example to github, I was able to see that the constraints were in fact over-determined. There was too much "this is equal to that", esp. in the area of vertical spacings/heights. I simplified the constraints, and was able to change to your code to this:
-(CGFloat)tableView:(UITableView *)tableView
heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0)
{
return 44;
} // else
UITableViewCell* cell =
[tableView dequeueReusableCellWithIdentifier:@"LargeCell"];
CGSize sz =
[cell.contentView systemLayoutSizeFittingSize:UILayoutFittingExpandedSize];
return sz.height;
}
If I'm not mistaken, that's exactly the sort of thing you are after, i.e. to let the constraints themselves dictate the height of the cell.
Separator
is messing with the height of the contentView
, either it should be disabled (and replaced with custom one if required) so that the contentView
height matches the height of the cell
or the constraints should be changed to more flexible considering that the contentView
height may mismatch the height of the cell
. Doing both would be even better.