Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove UITableView top inset when embedded in ContainerView?

I am currently working on an iPhone App. I now have a problem with the top spacing inset of a UITableView. See this screenshot:

App Running. See the space?

There should be no space between the table view cells and the buttons.

I do not know how to fix this. The UITableView is embedded in a ContainerView like this:

Storyboard View Controller

I think I got the container view constraints right. Top Space to Chapter Button is set to 0.

Container View Constraints

I tried to change some settings of the table view controller in storyboard. For example the Adjust Scroll View Insets. However it does not change anything when I disable that.

TableViewController Settings

I also tried to set the TableView insets directly in the code in viewDidLoad():

tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)

However this also did not fix it.

Can anyone help? I have no idea where to look.

like image 709
funkenstrahlen Avatar asked Jan 27 '16 11:01

funkenstrahlen


3 Answers

This can be solved by disabling auto adjustment of scroll view insets. However this setting has to be applied to the ViewController which contains the ContainerView (with the UITableView inside of it). It does not work when applied to the UITableView itself.

This can be done via Storyboard:

adjust scroll view insets

Or via code in viewDidLoad(): self.automaticallyAdjustsScrollViewInsets = false

like image 86
funkenstrahlen Avatar answered Nov 11 '22 22:11

funkenstrahlen


Since iOS 15 there's a new parameter which can introduce a top gap when using a section header. This can be removed with the following:

if #available(iOS 15, *) {
    tableView.sectionHeaderTopPadding = 0
}
like image 44
Leon Avatar answered Nov 11 '22 22:11

Leon


Try this Hope this work. hide View which contains the ContainerView.

self.automaticallyAdjustsScrollViewInsets = NO
like image 2
viratpuar Avatar answered Nov 11 '22 22:11

viratpuar