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
?
The only thing that worked for me was:
Swift:
Objective-C:
Also, I still had an extra space for the first section. That was because I was using the
tableHeaderView
property incorrectly. Fixed that as well by adding:Try changing the
contentInset
property thatUITableView
inherits fromUIScrollView
.It's a workaround, but it works
Another quick comment... even in XCode 6.1, there is a bug with vertical spaces appearing at the top of
UIScrollViews
,UITextViews
andUITableViews
.Sometimes, the only way to fix this issue is to go into the Storyboard and drag the problem control so it's no longer the first subview on the page.
(My thanks to Oded for pointing me in this direction... I'm posting this comment, just to add a few screenshots, to demonstrate the symptoms and fix.)
My answer is going to be more general answer, but can be applied on this as well.
If the root view (of the ViewController) or the first child (subview) of the root view is subclass of the UIScrollView (or UIScrollView itself), and if
framework will automatically set pre-calculated contentInset.
To avoid this you can do
but in my case I wasn't able to do this, because I was implementing SDK which has UIView component which can be used by other developers. That UIView component contains UIWebView (which has UIScrollView as the first subview). If that component is added as the first child in the UIViewController's view hierarchy, automatic insets will be applied by system.
I've fixed this by adding dummy view with frame (0,0,0,0) before adding UIWebView.
In this case system didn't find subclass of the UIScrollView as the first subview and didn't apply insets
I had the same fix as arielyz. Once I moved the UITableView to be not the first subview of the parent view, it went away. My space was 20 px, not 35.
I wasn't able to recreate it in a portrait xib, only a landscape xib. I'll file a radar bug later if I can reproduce it in a simple demo app.
try, you can deal with it!