1

So just like UITableViewCells, I wanted to create section headers who can provide their own height using Autolayout constraints. I used estimatedSectionHeaderHeight and sectionHeaderHeight = UITableViewAutomaticDimension on UITableView.

It seems to work pretty well, except for when I want to hide the section header entirely. As soon as I set the height constraint to anything below 0.3, the header resets to default height of 17.67. I've tried returning CGFloat.leastNonZeroMagnitude as suggested by many people. But it still resets to default height.

I have to return at least 0.5 px height for constraints to work.

The header view is simply a view with top,left,right,bottom constraints to superview, and a height constraint that I change as required.

I am not implementing heightForHeaderViewInSection because I want autolayouts to take precedence in determining header view height.

EDIT It's a Grouped UITableView.

Update My only solution so far is to implement heightForHeaderViewInSection and return either CGFloat.leastNormalMagnitude or UITableViewAutomaticDimension depending upon if I need to hide the headerView or let autolayouts decide its height when it's non-zero.

atastrophic
  • 3,153
  • 3
  • 31
  • 50
  • Are you returning the "auto-sizing" view in `viewForHeaderInSection`? If so, do you know at that point that you want it hidden? If so, you can return `nil` instead of returning a view at all... – DonMag May 01 '17 at 16:17
  • 1
    returning nil results in default section header height. – atastrophic May 01 '17 at 16:29
  • An option is to just create the section header logic as cells – Sentry.co May 18 '18 at 18:30

0 Answers0