2

I updated my iPhone to iOS 15 and Xcode to 13 version and now my app have a weird padding on top in all screens that has a tableView. enter image description here

How can I solve this problem?

M. Mansuelli
  • 1,083
  • 9
  • 19

3 Answers3

6

After a lot of research, I founded the answer in Apple developer documentation: https://developer.apple.com/documentation/uikit/uitableview/3750914-sectionheadertoppadding?language=objc

So, to solve this problem I added this code in all screen that I was using UITableView:

if #available(iOS 15.0, *) {
   tableView.sectionHeaderTopPadding = .zero
}

With this code the gap goes away.

M. Mansuelli
  • 1,083
  • 9
  • 19
6

If you want to remove this top padding in all views, you can call this code in AppDelegate:

if #available(iOS 15.0, *) {
    UITableView.appearance().sectionHeaderTopPadding = .zero
}
Eduardo Santi
  • 425
  • 1
  • 4
  • 13
  • 1
    Objc variant of the above: `if (@available(iOS 15.0, *)) { [[UITableView appearance] setSectionHeaderTopPadding:CGFLOAT_MIN]; }` – turingtested Oct 20 '21 at 07:58
2

The below code is fixed my issue

 if #available(iOS 15, *) {
        UITableView.appearance().tableHeaderView = .init(frame: .init(x: 0, y: 0, width: 0, height: CGFloat.leastNonzeroMagnitude))
    }
Metin Atalay
  • 1,375
  • 18
  • 28