Lekve
Lekve

Reputation: 168

iOS 11 Extra top space in UITableView

When I updated my app on iOS 11 SDK , TableView started behaving Weird , It is adding extra top space , but actually that extra space is Cell itself but it is not rendered , please look through attached image before ios 11 update and after. Thank you!

this is after ios 11 update

Before ios 11

Upvotes: 3

Views: 7146

Answers (5)

pandu
pandu

Reputation: 47

I had faced the extra top space issue, I had to club a bunch of answers to reach the solution. (5 hours of checking all answers given)

first if your concerned

Table view - mode is "Group" please change it to "Plain"

no need to do any changes to header or footer section, or add additional delegate methods related to them

Then in the ViewController that has your TableView in InterfaceBuilder - Uncheck Adjust Scroll View Insets - Uncheck Extend edges: Under Top Bars

*Also, make sure you are deleting derived data and re-installing your app in simulator or phone to reflect the changes done effectively.

UI changes sometimes don't reflect because of IDE also...

enter image description here

Upvotes: 1

Ben Kax
Ben Kax

Reputation: 466

only happened on iOS 11 for me, my fix:

self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];

OR

self.tableView.tableHeaderView = UIView(frame: CGRect(x:0,y:0,width:0,height:CGFLOAT_MIN))

Upvotes: 1

BLC
BLC

Reputation: 2290

Set new property contentInsetAdjustmentBehavior in your code, it would fix the problem.

if #available(iOS 11.0, *) {
    collectionView.contentInsetAdjustmentBehavior = .never
}

There is a new property on UIScrollView called contentInsetAdjustmentBehavior added in iOS 11 to determine adjust content offset

This property specifies how the safe area insets are used to modify the content area of the scroll view. The default value of this property is automatic.

Upvotes: 25

user5717376
user5717376

Reputation:

I don't know why but when I add table view programmatically that space occurs. All you need is returning empty view in viewForHeaderInSection

 func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    return UIView()
}

If you want zero space, add it too,

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return 0.01
}

Also, I realized that bug appears only in Swift4.

Upvotes: 6

Lekve
Lekve

Reputation: 168

It appears that adding gradient layer to TableView in iOS 11 creates this problem

Upvotes: -3

Related Questions