Alright, another UITableViewCell dynamic height problem, but with a little twist. Unfortunately I can\'t jump to iOS 8 only when released, otherwise the problem would be sol
I was in the same situation, and solved it to override the systemLayoutSizeFittingSize
function in the given cell and replace the aspectRation constraint to a height constraint. In the following example the mediaPlayerAspectRationConstraint
is added to the view during the view lifecycle and the mediaPlayerHeightContraint
is going to use to determine the right height of the cell (see the code below).
So, I used the
CGFloat height = [cell systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
instead of the [cell.contentView systemLayoutSizeFittingSize:]
.
- (CGSize)systemLayoutSizeFittingSize:(CGSize)targetSize {
self.mediaPlayerHeightContraint.constant = CGRectGetHeight(self.experienceMedia.frame);
//Lets replace it with an exact height constraint (workaround).
//To remove the Unable to simultaneously satisfy constraints. exceptions
[self.contentView layoutIfNeeded];
[self.experienceMedia removeConstraint:self.mediaPlayerAspectRationConstraint];
[self.experienceMedia addConstraint:self.mediaPlayerHeightContraint];
[self setNeedsUpdateConstraints];
CGSize res = [self.contentView systemLayoutSizeFittingSize:targetSize];
[self.contentView layoutIfNeeded];
[self.experienceMedia removeConstraint:self.mediaPlayerHeightContraint];
[self.experienceMedia addConstraint:self.mediaPlayerAspectRationConstraint];
[self setNeedsUpdateConstraints];
return res;
}