So just like UITableViewCell
s, 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.