UITableViewCell rounding error with NSAutoresizingMaskLayoutConstraint, but size correctly set in Storyboard AND heightForRowAtIndexPath:

后端 未结 2 943
失恋的感觉
失恋的感觉 2021-01-14 10:37

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

相关标签:
2条回答
  • 2021-01-14 10:51

    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.

    0 讨论(0)
  • 2021-01-14 11:02

    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.

    0 讨论(0)
提交回复
热议问题