Reputation: 7658
Evening,
I have the following design:
When a collection view is empty I would like the row, or the collection view to autoresize to 0.
Currently I got this:
So I want the orange box autoresizing to height = 0 when there aren't blue box.
I know that I should use a constraint of collectionView Height and set to 0 when is empty.
But i have the outlet in the table cell and the collection delegate into the view controller. And I don't know how to accomplish this.
Any tips? With some code example please :P
Upvotes: 1
Views: 1194
Reputation: 735
Try to use
func tableView(_ tableView: UITableView,
heightForRowAt indexPath: IndexPath) -> CGFloat
function. In this function, for the corresponding row, return 0.
Upvotes: 2
Reputation: 17414
I don't think it's possible to resize collectionView depending on its content automatically.
What you can actually do is add constraint of height to your CollectionView and set it to 0 if it's empty.
Then, your cell will have intrinsic height, if you connect CollectionView bottom and top to it accordingly (which you possibly already done)
The last step will be to set tableView.rowHeight to UITableViewAutomaticDimension. Probably it will work :)
Upvotes: 3