I have a viewcontroller which manages an uitableview with uicollectionviews in the uitableviewcells.
However, the uicollectionviews may contain varying numbers of items. Therefore I need to adjust the height of the uicollectionviews.
But when I try to do this the heights of the other uicollectionviews are also changed.
The uicollectionview is bound by an IBOutlet, as well as the constraint for the height of the collection view.
I'm setting the height of the collectionview in
tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath)
:
cell.collectionView.reloadData();
cell.collectionViewHeight.constant = cell.collectionView.collectionViewLayout.collectionViewContentSize.height;
cell.collectionView.setNeedsLayout();
cell.collectionView.layoutIfNeeded();
First I'm reloading the data and then I'm setting the height constraint and finally I'm applying the new layout.
This seems to work at first - but I recognized that the other cells are also effected - probably because I'm dequeueing the reusable cell. But how can I change my code, such that it works?