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 is 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
?
I'm assuming that is just part of the new
UITableViewStyleGrouped
styling. It is in all grouped table views and there doesn't seem to be any direct way to control that space.If that space is being represented by a
UIView
, it would be possible to search through all thesubviews
of theUITableView
to find that specific view and edit it directly. However, there is also the possibility that that space is just a hardcoded offset before headers and cells start and there won't be any way to edit it.To search through all subviews (I would run this code when the table has no cells, to make it a little easier to read the output):
I have found the cause of my original bug and created a sample project showcasing it. I believe there is an iOS7 bug.
As of iOS7, if you create a UITableView with the Grouped style, but do not have a delegate set on first layout, then you set a delegate and call reloadData, there will be a 35px space at the top that will never go away.
See this project I made showcasing the bug: https://github.com/esilverberg/TableViewDelayedDelegateBug
Specifically this file: https://github.com/esilverberg/TableViewDelayedDelegateBug/blob/master/TableViewDelayedDelegateBug/ViewController.m
If line 24 is active,
there will be an extra 35 px space at the top. If line 27 is active and 24 is commented out,
no space at the top. It's like the tableView is caching a result somewhere and not redrawing itself after the delegate is set and reloadData is called.
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 thetableHeaderView
, instead of doingself.tableView.tableHeaderView = nil;
, I do:I like this solution better than setting a somewhat arbitrary
contentInset.top
because I use thecontentInset.top
dynamically as well. Having to remember to remove an extra 35px whenever I recalculatecontentInset.top
is tedious.Swift: iOS I had tableview on scroll view .. when I was click "Back" on the same screen. Scroll view take more space on top.. to solve this I have used :
A Boolean value that indicates whether the view controller should automatically adjust its scroll view insets. Default value is true, which allows the view controller to adjust its scroll view insets in response to the screen areas consumed by the status bar, navigation bar, and toolbar or tab bar. Set to false if you want to manage scroll view inset adjustments yourself, such as when there is more than one scroll view in the view hierarchy.
Uncheck "Adjust Scroll View insets"