0

I use the method as follows

I have just tried below lines of code, dynamically set the UITableViewHeaderFooterView height size.

self.tableView.estimatedSectionHeaderHeight = 100 self.tableView.sectionHeaderHeight = UITableViewAutomaticDimension

I have the following problems

In iOS9, iOS10 can run normally, and can display properly. But can not be displayed correctly in iOS8, and the following error is displayed:

enter image description here

My analysis is as follows:

From the error prompt, I can see that the problem is NSLayoutConstraint: 0x7f8498d7b890 _UITableViewHeaderFooterContentView: 0x7f8498cb9200.height == 0

But I have never made any Constraints to UITableViewHeaderFooterContentView

How should I fit iOS8?

ChildrenGreens
  • 119
  • 1
  • 9
  • Call the `updateConstraintsIfNeeded` method when you return your cell inside the `table view cell for row at` method. `cell.updateConstraintsIfNeeded() return cell` This step is NOT needed for iOS 9+ – Vignesh Davins Jul 07 '17 at 05:45
  • This method does not work – ChildrenGreens Jul 07 '17 at 05:58
  • In order to make UITableViewAutomaticDimension work you have to set all left, right, bottom, and top constraints relative to cell container view. Check did u added all four constraints... – Vignesh Davins Jul 07 '17 at 06:03

1 Answers1

1

You need to use the UIView systemLayoutSizeFittingSize:

-(void)viewDidLayoutSubviews
    {
        [super viewDidLayoutSubviews];

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

        CGRect headerFrame = ViewHeader.frame;
        headerFrame.size.height = height;
        ViewHeader.frame = headerFrame;
        [tbl setTableHeaderView:ViewHeader];
    }
Arpit Javerya
  • 473
  • 3
  • 12