0

I have a UITableViewHeader which contains a UILabel (dynamic height - can be one line or mulitple lines) and a custom UICollectionView which shows a UILabel in each UICollectionViewCell. Depending on which device is used, these UICollectionViewCells can span over one line or they can be on two or three lines. That all doesn't matter that much.

My problem is in the heightForHeaderInSection method. As this gets called before the frame is set (print(headerView.frame.height) returns 0.0), I can't properly return the correct height. I am trying to access the headerView.frame.height so it can be set dynamically, but I fail to do so. I have looked into viewDidLayoutSubviews, but then I would have to store it as a CGFloat and force heightForHeaderInSection to be called again.

I am pretty sure there must be a way to do this more easily. I also tried looking in to UITableView.automaticDimension, but this hasn't brought me to the resolution either. Any suggestions?

Bhavesh Nayi
  • 3,626
  • 1
  • 27
  • 42
PennyWise
  • 595
  • 2
  • 12
  • 37
  • this might help [https://stackoverflow.com/a/15078805/6654562] – Iva Apr 29 '19 at 07:37
  • Are you using viewforheaderinsection method to create the header view? – RajeshKumar R Apr 29 '19 at 08:20
  • Yes. But I am now looking into setting the tableHeaderView because it should only show on top and there is only one section. However, some problem, I seem unable to find "where" to set the dynamic height. – PennyWise Apr 29 '19 at 08:22

0 Answers0