iOS 15 Gap between navigation bar and table view

Hi!

With iOS 15 beta some custom UITableViewControllers has decided to add a gap between the navigation bar and the table view while others don't. They are created the same and added the same with the showViewController:sender: method.

I found a workaround by removing

[super viewWillAppear:animated];

in the viewWillAppear: method but I don't find this to be a good solution.

Does anyone have this issue as well or know a solution?

Best regards,

dumle

Answered by Galvin Li in 687940022

I find a way to solve the issue and wrote an article about this. https://medium.com/@GalvinLi/fix-the-table-header-gap-in-ios-15-197debb92608

In short way: Just set a tableHeaderView before table loaded.

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];
}

or change it globally

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [UITableView appearance].tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];
    return YES;
}

i think what you might be seeing (which i also have seen) is that for ios 15 for the Plain table view style they add a Section header padding by default, I wish it was a checkbox or something so we dont have to have it (especially by default) since alot of us are using custom section headers, BUT they did add a function to manually set it in your viewDidLoad

     if (@available(iOS 15.0, *)) {
       [self.tableView setSectionHeaderTopPadding:0.0f];
     }

this should remove the padding or that "gap" you are seeing.

39

Managed to recreate the issue in a test project and noticed that the problem might be when the app is using a network call. Using AFNetworking framework to make REST calls. I am using the Xcode 13 beta 2 and running the app on iOS 15 on the simulator.

Link to Github Repo

Will provide an image as well, the section header should only be 30 pt/px but it's clearly not.

     if (@available(iOS 15.0, *)) {        [self.tableView setSectionHeaderTopPadding:0.0f];      }

helped me to resolve the issue, thank you lmDeveloper1

I faced the same issue as well and checked the default header padding being set.Though the default sectionHeaderTopPadding is -1.0f it is still adding some space on the top of the section header. The default value needs to be 0.0f so that we don't have to make the change in our project. I hope they make the change.

It doesn't work for me

tableView.sectionHeaderTopPadding = 0.0

I am having the same problem. I noticed that this happens on an Xcode project that has been recently created after iOS 14.6 update.

From WWDC21, session: “What's new in UIKit“ (I'm pasting from the transcript)

We have a new appearance for headers in iOS 15. For plain lists, section headers now display seamlessly in line with the content, and only display a visible background material when becoming pinned to the top as you scroll down. In addition, there's new padding inserted above each section header to visually separate the sections with this new design.

To remove this padding globally for all plain table views... 

if #available(iOS 15.0, *) {
    UITableView.appearance().sectionHeaderTopPadding = CGFloat(0)
}

Note: this does not appear to effect the padding for grouped table views. (Thankfully!)

13

This is a confirmed bug by Apple and they are looking into it. Release of the fix is unknown.

Accepted Answer

I find a way to solve the issue and wrote an article about this. https://medium.com/@GalvinLi/fix-the-table-header-gap-in-ios-15-197debb92608

In short way: Just set a tableHeaderView before table loaded.

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];
}

or change it globally

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [UITableView appearance].tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];
    return YES;
}

This removes the unwanted section header space.

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

This one worked for me:

if (@available(iOS 15.0, *)) {
        [UITableView appearance].sectionHeaderTopPadding = 0;
}

Yes, same issue for me

Check your Launchscreen images sizes and check your Attribute inspector Portrait options, it should be enabled in iOS 15 improved some additional launch images

iOS 15 Gap between navigation bar and table view
 
 
Q