Search code examples
iosswiftuitableviewcell

How to make the cells inside of a tableview begin lower down?


I have a tableview. Right now the first cell will begin right at the top of the tableview, but I want it to start some number below the top of the tableview so that I can addSubview() in that spot without covering content in the first cell.

Below you can see what I want to achieve.

The rectangle in the center represents the cells, the line at the top represents the top most of the tableview.

enter image description here


Solution

  • Short answer: You don't. The contents of a table view belong to the table view. You should not try to add subviews to a table view.

    As @rickramirr says, you either need to position your table view lower on the screen, or use a header view that contains the contents you want.

    (If you decide to position your table view lower down, need to either not manage your table view with a UITableViewController, or have a UITableViewController as a child view controller of the screen's main view controller. A UITableViewController is kind of dumb, and only knows how to manage a table view and nothing else.)