Starting in iOS7, there is additional space at the top of my UITableView
's which have a style UITableViewStyleGrouped
.
Here is an example:
The tableview starts at the first arrow, there are 35 pixels of unexplained padding, then the green header is a UIView
returned by viewForHeaderInSection
(where the section is 0).
Can anyone explain where this 35-pixel amount is coming from and how I can get rid of it without switching to UITableViewStylePlain
?
In iOS 11 and later:
tableView.contentInsetAdjustmentBehavior = .never
Short answer is that this extra padding is probably due to the table view header (not the section header), and that UITableView doesn't like to be assigned a header with a height of 0.0.
A view that presents data using rows in a single column.
I was helped by the following:
YouStoryboard.storyboard > YouViewController > Attributes inspector > Uncheck - Adjust scroll view insets.
I played around with it a bit more and it seems like this is a side-effect of setting the tableView's tableHeaderView = nil
.
Because my tableView has a dynamically appearing tableHeaderView
, when I need to hide the tableHeaderView
, instead of doing self.tableView.tableHeaderView = nil;
, I do:
self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.tableView.bounds.size.width, 0.01f)];
I like this solution better than setting a somewhat arbitrary contentInset.top
because I use the contentInset.top
dynamically as well. Having to remember to remove an extra 35px whenever I recalculate contentInset.top
is tedious.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With