UITableviewHeader hides top cells

91 Views Asked by At

I'm setting the tableHeaderView of a UITableView, but it is hiding the top cells of the table. In my case, I want to show tableview header I have used all possible solutions but not works. Please help.

UIView *headerView = self.headerView;

[headerView setNeedsLayout];
[headerView layoutIfNeeded];
CGFloat height = [headerView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;

headerView.frame = ({
    CGRect headerFrame = headerView.frame;
    headerFrame.size.height = height;
    headerFrame;
});



NSLog(@"Header Frame : %@",headerView);
self.reviewsTableView.tableHeaderView = headerView;

View debugger screenshot

3

There are 3 best solutions below

0
AudioBubble On BEST ANSWER

I was work around this issue, In my case real issue was with constraints in the storyboard.

You have to reset constraint from the storyboard.

Or if you are setting it programmatically then you needed to call updateConstraintsIfNeeded method after setting of constraints to the widget.

1
Deepak Kumar On

try writing the below lines at the end [self.tableView setNeedsUpdateConstraints]; [self.tableView updateConstraintsIfNeeded];

if you set headerview using storyboard then it will become easy

2
Kunal On

Don't do it in viewDidLoad. Instead do it in viewWillLayoutSubviews. This works for me.

- (void)viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];
    [_headerWrapper setNeedsLayout];
    [_headerWrapper layoutIfNeeded];
    CGFloat height = [_headerWrapper systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
    CGRect headerFrame = _headerWrapper.frame;
    headerFrame.size.height = height;
    _headerWrapper.frame = headerFrame;
    _tableView.tableHeaderView = _headerWrapper;
}