UITableView's contentSize is wrong

on iOS 11 .I wtire this code:


- (void)viewDidLoad

{

[super viewDidLoad];

self.tableView.contentOffset = CGPointMake(0, _searchBar.height);

self.tableView.tableHeaderView = _searchBar;

}


After the tableView ‘layoutSubViews was executed, I get the tableView's contentSize.But the contentSize is wrong

In iOS 11, table views use estimated heights by default. This means that the contentSize is just as estimated value initially. If you need to use the contentSize, you’ll want to disable estimated heights by setting the 3 estimated height properties to zero: tableView.estimatedRowHeight = 0 tableView.estimatedSectionHeaderHeight = 0 tableView.estimatedSectionFooterHeight = 0

UITableView's contentSize is wrong
 
 
Q