Reputation: 14370
I have a Layout which displays 3 types of data in a different way: I have types, which come under each other, I have locations, which also come under each other, and then I have times, which flow next to each other, and take all the space they need. An example:
I thought about having this as 3 UICollectionViews
, where they try to size themselves. But I have tried (and failed) to do this.
All cells are xibs and I set the constraints when I add the data. This is the code I perform when I set the data in my cell:
hallsCollectionView.dataSource = TheaterHallCollectionViewDataSource(ticketType)
hallsCollectionView.reloadData()
hallsCollectionView.collectionViewLayout.invalidateLayout()
hallsCollectionView.setNeedsLayout()
hallsCollectionView.layoutIfNeeded()
hallsCollectionViewHeightConstraint.constant = hallsCollectionView.collectionViewLayout.collectionViewContentSize.height
layoutIfNeeded()
But when I set a breakpoint, the collectionViewContentSize
is not correct, it is always the height when there is only one item, even though I set the datasource before laying out the collectionviewcells.
Upvotes: 1
Views: 89
Reputation: 14370
So I think I found what I had to do, I needed to call layoutIfNeeded()
on the superview, and another thing was that the UICollectionViewCell
still had the frame from the xib it came from...
On another note, I have moved this from being 3 levels deep to only 2, as I can simplify the "type 1" and "type 2" headers to being just cells. I currently have it as an extra cell in each section, but I can see myself changing this around to being a tableview in the near future, as they are easier to work with for header cells, and they don't need information for their widths.
If anyone wants to explain to me why these things are the way they are, please do.
Upvotes: 1