Nate23VT
Nate23VT

Reputation: 423

UITableview adding white space at top of view

I am running into a weird issue with a tableview adding an empty "white space" at the top. I have the table view constraint bound to 5 of the segmented control field above.

I am new to Swift and I am not sure how to further debug these types of UI issues. I have checked the constraints and I do not think that is the issue. The storyboard does not show this additional white space... where is it coming from?

EDIT: It appears to only create the whitespace on iOS10. Looks fine on iOS11.

Application home screen

EDIT: xCode screen

xCode Screen

Upvotes: 0

Views: 1406

Answers (4)

anomaddev
anomaddev

Reputation: 9

This is the updated 2022 iOS 15 solution

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

Upvotes: 0

Raimundas Sakalauskas
Raimundas Sakalauskas

Reputation: 2294

EDIT: I see someone else took my code and got selected already but for the sake of providing full answer here it is.

This behavior is caused by automatic insets by the ios platform. There are two options here:

  1. If you snap your table view to bottom edge of navbar be sure to execute the code below. It will disable automatic insets on both iOS 11 and older iOS versions.
  2. Otherwise you can snap your tableview to edge of the view and omit the code, because the purpose of the code is to compensate the size of navbar/tabbar, and since you snap your tableview behind/under them, you need that compensation to happen.

Code in case of #1 scenario that works on iOS 11 and older platforms.

Objective-c:

if (@available(iOS 11, *)) {
    self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
} else {
   self.automaticallyAdjustsScrollViewInsets = NO
}

Swift:

if #available(iOS 11.0, *) {
    tableView.contentInsetAdjustmentBehavior = .never
} else {
    automaticallyAdjustsScrollViewInsets = false
}

Upvotes: 2

Suneet Tipirneni
Suneet Tipirneni

Reputation: 839

It seems that the automatic content insets on the table view are activated, you can stop this behavior by adding this code to your view controller.

  if #available(iOS 11, *) {
     self.tableView.contentInsetAdjustmentBehavior = .never;
  }else{
     self.automaticallyAdjustsScrollViewInsets = false
  }

Upvotes: 1

Xcoder
Xcoder

Reputation: 1453

Try to look in the 'attribute inspector' (in the right menu) of the Participants ViewController. Check for the option 'Extend Edges' and uncheck the 'Under Top Bars', and then relocate your tableview.

Upvotes: 0

Related Questions