7

With iOS 15 beta and Xcode 13 beta 2 some custom UITableViewControllers has decided to add padding between the navigation bar and the table view.

Steps to reproduce:

Add two UITableViewControllers so the structure looks like this: UINavigationController -> UITableViewController -> UITableViewController.

Add table view delegate method heightForHeaderInSection and return a small value.

In viewDidLoad or viewWillAppear methods make a API call.

Actions to solve the problem:

[self.tableView setSectionHeaderTopPadding:0.0f]; // Not working

[self.tableView setContentInset:-35.0f]; // Works but is not dynamic

Tested on Xcode 13 beta 2, iOS 15 beta 2, iPhone 12 Simulator, iPhone Xs

Demo project showing the issue: Github link

The header section should only be 30 pt/px but it's clearly not:

enter image description here

Link to original Apple Developer forum thread

dumle
  • 79
  • 1
  • 4
  • iOS 15 is beta. Make sure to file a bug with Apple. – koen Jul 05 '21 at 17:10
  • 1
    Check my article, tested on your demo project and problem gone. https://medium.com/@GalvinLi/fix-the-table-header-gap-in-ios-15-197debb92608 – Galvin Sep 17 '21 at 10:09

1 Answers1

7

You can try using UITableView.sectionHeaderTopPadding like this -

if #available(iOS 15, *) {
    tableView.sectionHeaderTopPadding = 0
}
Tarun Tyagi
  • 9,364
  • 2
  • 17
  • 30