Swift set height of table

asheyla picture asheyla · Oct 11, 2016 · Viewed 7.4k times · Source

I have this table for which I want a certain height even when I only have one row. I want to make it scrollable (empty space at the bottom) even when I do not have enough rows to cover the whole screen.

I think I should work with:

tableView.contentSize.height = 2000

But either I do not know where I should put it(should I reloadData for the table after?) or I have the wrong idea of how to do this.

Can anybody help?

EDIT: I have this view inside the table view which in some cases might be higher than the table and in this case I can not scroll it all. This is why I need to change the table in scroll height.

On iOS 10 it works as intended, but I have to fix it for iOS 8 and 9 also.

Answer

random picture random · Oct 11, 2016

This has been tested and works:

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)
    tableView.contentSize.height = 2000
}

Example: enter image description here