gndimitro
gndimitro

Reputation: 107

UITableView still leaves space on top even after disabling contentInset Xcode 9.4.1

I'm trying to place a table view inside of a basic view controller without any padding on the top and nothing I've tried has worked, no matter what I do there is a gap up top. I placed the following code in my viewDidLoad() for the view controller:

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

I've gone into storyboard and disabled those settings as well manually: View Controller Table View

I do have custom cells I'm not sure if that matters, I do add insetting to the cells but even when I remove that code I have that gap.

Here's the code I customized for my cells:

override func layoutSubviews() {
        super.layoutSubviews()
        contentView.frame = UIEdgeInsetsInsetRect(contentView.frame, UIEdgeInsetsMake(cellSpacingHeight, 0, 0, 0))
    }

I've spent a couple hours googling around and I can't figure it out. I'm using the latest swift and Xcode to build this. I even tried to print the values for the tableView's content inset and it came up as all 0s. Does anyone know why I still have the offset or inset up top in my table view?

Upvotes: 1

Views: 151

Answers (1)

gndimitro
gndimitro

Reputation: 107

Wow okay so I finally figured it out, I had set the table view style to Grouped at some point instead of Plain. Once I made it plain, everything worked, I hope this might help someone else in this position!

Upvotes: 2

Related Questions