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

后端 未结 2 952
失恋的感觉
失恋的感觉 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.

提交回复
热议问题