Patrick Patrick - 2 months ago 6x
iOS Question

UITableViewcontentInset: when scrolling the table to the top, rows are still visible above first header

I've a table made of 1 header and 1 row in sequence:


I've set
to lower the beginning position of the table the content:

self.detailTableView.contentInset = UIEdgeInsetsMake(30.0, 0.0, 0.0, 0.0);

It works well, however, when scrolling the table, the content of the rows of the table is visible above the first header. Instead of disappearing, they are visible inside the top edge of 30 pixels. How to hide them instead? So that the scrolling works correctly.


I assume you have sticky headers in the table view.

If you want to add padding on top you can just set the table header view:

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