Auto layout constraints issue on iOS7 in UITableViewCell

I had this problem as well.. It appears that the contentView’s frame doesn’t get updated until layoutSubviews is called however the frame of the cell is updated earlier leaving the contentView’s frame set to {0, 0, 320, 44} at the time when the constraints are evaluated.

After looking at the contentView in more detail, It appears that autoresizingMasks are no longer being set.

Setting the autoresizingMask before you constrain your views can resolve this issue:

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.contentView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
        [self loadViews];
        [self constrainViews];
    }
    return self;
}

Swift5, ios14:

contentView.autoresizingMask = [.flexibleHeight, .flexibleWidth]

Leave a Comment