I know this is already asked in many threads but none of the solutions are working for me. Problem scenario is: I have a collectionview in tableview cell. The constraints on collection view are as: Collectionview top, leading, trailing and bottom constraint to superview and heightconstraint (with priority 999). Changing the height of collection view as:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: GalleryCollectionViewCell.identifier, for: indexPath) as? GalleryCollectionViewCell {
collectionViewHeightConstraint.constant = collectionView.contentSize.height
self.layoutIfNeeded()
return cell
}
return UICollectionViewCell()
}
On a button click the tableview is reload and when collectionview height constraint value is printed, it comes true but the tableview cell is not getting exact content size. But when i scroll then the tableview cell gets the exact size.
PS: Also tried using :
collectionViewHeightConstraint.constant = collectionView.collectionViewLayout.collectionViewContentSize.height