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
?
Simply add the following to your viewDidLoad in your VC:
While using grouped TableView use this to avoid border cutting in viewWillAppear
A lot of the previous answers above are too hacky. They would break at anytime in the future if Apple decides to fix this unexpected behavior.
Root of the issue:
a
UITableView
doesn't like to have a header with a height of 0.0. If what's you're trying to do is to have a header with a height of 0, you can jump to the solution.even if later you assign a non 0.0 height to your header, a
UITableView
doesn't like to be assigned a header with a height of 0.0 at first.Solution:
Then, the most simple and reliable fix is to ensure that your header height is not 0 when you assign it to your table view.
Something like this would work:
Something like this would lead to the issue at some point (typically, after a scroll):
For IOS 7 if you are allocing a tableview in a view controller you may look into
your problem seemed similar to mine
Update:
Swift in iOS 9.x:
Swift 3 :
I think making UIEdgeInsets -35 0 0 0 is tedious. In my case, I implemented tableView: heightForHeaderInSection: method and it has a potential to return 0.
When I changed 0 to 0.1f, the problem just went away.
This is how it can be fixed easily in iOS 11 and Xcode 9.1 through Storyboard:
Select Table View > Size Inspector > Content Insets: Never