I have created a test project in order to verify this problem. In the project storyboard I have two scenes. One scene is based on the initial ViewController that was added to the single view application when the project was created. The second scene was created by dragging a UITableViewController onto the storyboard.
In both scenes, I believe I have configured the prototype cell so it should auto size. When I set the initial ViewController to the one based on the UIViewController, the UITableViewCell do not show / size correctly. (See below)
However, when I set the initial ViewController to the one based on the UITableViewController, everything works fine. (see below)
The code / project is very simple and I am hoping someone has seen this and can tell me why the auto size for the UITableViewCell is not working correctly when the class is based on UIViewController verses a UITableViewController. Any help would be greatly appreciated. It appears I cannot upload the project here so I will try to get it uploaded to another location and update the question with a link.
To answer standard questions
Both prototype cells have two UILabel in them
The first UILabel has left, top, right and bottom constraints specified.
The second UILabel has left, right and bottom constraints specified.
Both classes set the estimatedRowHeight to a number and the rowHeight to UITableViewAutomaticDimension
All UILabel have their lines property set to 0
The first UILabel in both scenes has its Line Breaks set to Word Wrap
The second UILabel in both scenes has its Line Breaks set to Truncate Tail.
Below is a screen shot of the scene in interface builder. Left is based in UIViewController, right is based on UITableViewController
Here is a link to the code I hope: Sample Project
So I have found the "silver bullet" that seems to resolve a great number of challenges regarding auto layout of prototype cells.
In the cellForRowAtIndexPath function I added the following line of code right before I return the cell:
lobj_NearbyLocationEntry!.layoutIfNeeded()
(lobj_NearbyLocationEntry is the name of my cell variable I am returning.)
When I do this, the auto layout for my table works fine. On a side note, I found a defect in the code that uses the UITableViewController also. Once the data loads and it all looks good, if you scroll down and then scroll back up, you will see a couple of the cells are now not laid out correctly. Putting this line of code in that view controller's code also resolved that layout problem.
I hope this helps many people who are sitting there trying to figure out why their app is not auto laying out a tableView cell correctly. :)
For Me It Works
Give upper UILabel (right,top,left) constraints
Give lower UILabel (right,top,left,bottom) constraints
In Custom UITableViewcell
override func awakeFromNib() {
super.awakeFromNib()
up.lineBreakMode = NSLineBreakMode.ByWordWrapping // Label outlet
down.lineBreakMode = NSLineBreakMode.ByWordWrapping // Label outlet
up.numberOfLines = 0
down.numberOfLines = 0
// Initialization code
}
EDIT
InUITableViewController
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
In UIViewController
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
I am working on an app, which has implements a Search Display Controller. The search results table view, doesn't behave right all the time, and I'm trying to solve this issue from a few days. Here is a screen recording of the behavior.
I'm not modifying the frame or bounds of the table view. I'm only resigning first responder when there is no text in the search field, and calling the [searchDisplayController setActive: animated: ] method.
Please help me out.
Instead of setting the scrollIndicatorInsets and contentInsets of the searchResultsTableView when the keyboard hides, putting it within the 'willShowSearchResultsTableView:' delegate method fixed it for me:
- (void)searchDisplayController:(UISearchDisplayController *)controller willShowSearchResultsTableView:(UITableView *)tableView
{
[tableView setContentInset:UIEdgeInsetsZero];
[tableView setScrollIndicatorInsets:UIEdgeInsetsZero];
}
Solved this issue by using my own TableView instead of SearchResultsDisplayController's table view. Placed a new tableview on top of my previous tableview, and showing and hiding the search table view based on the delegates of the Search Bar (textDidChange).
I adopted this workaround, as I failed to solve the mysteries of layout problems in SearchResultsTableView.
I was getting what seems to be a very similar behaviour, but it only happened when running in the device (iPhone or iPad), but not in the simulator (both in iOS 8, Xcode 6.0.1, using Swift).
For some reason, when inputting a search text the contentInset.bottom and scrollIndicatorInsets.bottom of my searchResultsTableView didn't return to its original value after dismissing the keyboard. Each time the keyboard was shown and then dismissed, this value would increase by the keyboard's height and the space would get increasingly larger. I don't know what causes this, as I never fiddle with insets in the code. I'm suspecting it is some weird constraint going haywire, but I couldn't find it.
What solved for me was to programatically set the bottom insets to zero, whenever the keyboard was dismissed:
searchController.searchResultsTableView.contentInset.bottom = 0
searchController.searchResultsTableView.scrollIndicatorInsets.bottom = 0
I know this is only a workaround. Hope it helps in your case.
I'm doing very similar to #ricardoaraujo, but find that when I scroll back down to the bottom of the list, the last few cells are off the bottom of the screen (about 200px worth, therefore 1 x keyboard.height).
The frame of the searchResultsTableView is perfect (checked by both logging and using the new Debug View Hierarchy mode), and the contentInset is set to UIEdgeInsetsZero.
You'll probably therefore notice the same thing, but short of creating your own UITableView to display the results (as in #Vignesh's answer), there doesn't seem to be a nice way around it.
This does not happen on iOS7, so hopefully will be fixed in iOS8.0.3. Will check radar.
#Vignesh good that you got your problem solved, but UISearchDisplayController does that for us. It's true that it is a keyboard missing calculation issue, so I just had to set the contentInset and scrollIndicatorInsets back to UIEdgeInsetsZero when my keyboard goes way.
func searchDisplayController(controller: UISearchDisplayController, didHideSearchResultsTableView tableView: UITableView) {
NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardDidHideNotification, object: nil)
}
func searchDisplayController(controller: UISearchDisplayController, willShowSearchResultsTableView tableView: UITableView) {
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillHide", name: UIKeyboardDidHideNotification, object: nil)
}
func keyboardWillHide() {
let tableView = self.searchController.searchResultsTableView
tableView.contentInset = UIEdgeInsetsZero
tableView.scrollIndicatorInsets = UIEdgeInsetsZero
}
It's just another workaround, but it's working well so far on iOS7 +
Swift version:
func searchDisplayController(controller: UISearchDisplayController, willShowSearchResultsTableView table: UITableView!) -> Void {
table.contentInset = UIEdgeInsetsZero
table.scrollIndicatorInsets = UIEdgeInsetsZero
}
Based on answer of #user2795503
I'm picking up some iOS programming and am trying to put a UITableView into a storyboard. Unfortunately, I am trying to put the content at the top of the view but it is putting in some space. I have tried to adjust the values in the inspector for View -> Mode but this doesn't seem to have any effect.
I have made the background green and put a border color to show the issue. I'm not a sophisticasted iOS dev, so I'd assume that this is the simplest solution and not something complex. How do I make the contents of the table view sit flush with the top? I've seen this Why is there extra padding at the top of my UITableView with style UITableViewStyleGrouped in iOS7 but not sure if it's related.
thx for any help
Edit #1
Updated with changes and screen shot of properties for this table view
Yes, that other question is very much related. UITableViewStyleGrouped divides each section into a "group" by inserting that extra padding…similar to what it did pre-iOS7, but clear instead of colored by default, and just at the top instead of all the way around. If you don't want the padding by default, use UITableViewStylePlain.
Otherwise, if you need to keep the style the same, do what this other posted from that link recommended and change the content inset:
self.tableView.contentInset = UIEdgeInsetsMake(-36, 0, 0, 0);
Or do what this poster suggested and set the tableHeaderView's height to .-1, i.e. nearly 0:
self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.tableView.bounds.size.width, 0.01f)];
Go to the attributes inspector of the View Controller by selecting the xib or the controller in Storyboard. Uncheck the Adjust Scroll View Insets in Layout. It will solve the problem
Everybody keeps talking about this self.automaticallyAdjustsScrollViewInsets option.
However this did not work for me at all. What did work for me, was setting the "Content Insets" property to Never.
Such an annoying problem.
In Swift, you just need to set the below property to false.
self.automaticallyAdjustsScrollViewInsets = false
It is very easy and worked for me perfectly.
Select a controller in Story Board in which you placed UITableView.
YouStoryboard.storyboard > YouViewController > Attributes inspector > Uncheck - Adjust scroll view insets.
Make sure you select UIViewController not UITableView.
Swift :
override func viewWillAppear(animated: Bool) {
self.edgesForExtendedLayout = UIRectEdge.None
OR
self.moduleListTableView.contentInset = UIEdgeInsetsMake(-64, 0, 0, 0);
OR
self.automaticallyAdjustsScrollViewInsets = false
}
try this....
self.tableView.contentInset = UIEdgeInsetsMake( 20, 20 , 0, 0)
in swift 3.0, i hope will help you
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return CGFloat.leastNormalMagnitude
}
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return CGFloat.leastNormalMagnitude
}
This is how it can be fixed easily through Storyboard:
Select Table View > Size Inspector > Content Insets: Never
Cause of this 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.
In ViewDidLoad:-
self.edgesForExtendedLayout = UIRectEdge.None
self.automaticallyAdjustsScrollViewInsets = false
No Need For Something Like This :-
self.myTableview.contentInset = UIEdgeInsetsMake(-56, 0, 0, 0)
In heightForHeaderInSection delegate:-
if section == 0
{
return 1
}
else
{
return 40; // your other headers height value
}
In viewForHeaderInSection delegate :-
if section == 0
{
// Note CGFloat.min for swift
// For Objective-c CGFLOAT_MIN
let headerView = UIView.init(frame: CGRectMake(0.0, 0.0, self.myShaadiTableview.bounds.size.width, CGFloat.min))
return headerView
}
else
{
// Construct your other headers here
}
Maybe you have more than one parent navigation controller? If that's the case, uncheck other parent navigation controllers' "Show Navigation Bar".
This worked for me in swift:
tableView.tableHeaderView = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: CGFloat.leastNormalMagnitude))
For iOS 15.0+,
use this for removing extra padding at the top
if #available(iOS 15.0, *){
self.tableView.sectionHeaderTopPadding = 0.0
}
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?
Update (Answer):
In iOS 11 and later:
tableView.contentInsetAdjustmentBehavior = .never
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.
Try changing the contentInset property that UITableView inherits from UIScrollView.
self.tableView.contentInset = UIEdgeInsetsMake(-20, 0, 0, 0);
It's a workaround, but it works
For IOS 7 if you are allocing a tableview in a view controller you may look into
self.edgesForExtendedLayout = UIRectEdgeNone;
your problem seemed similar to mine
Update:
Swift in iOS 9.x:
self.edgesForExtendedLayout = UIRectEdge.None
Swift 3 :
self.edgesForExtendedLayout = UIRectEdge.init(rawValue: 0)
self.automaticallyAdjustsScrollViewInsets = NO;
try, you can deal with it!
You could detect if your app is running iOS7 or greater and add this two methods in your table view delegate (usually in your UIViewController code)
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return CGFLOAT_MIN;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return CGFLOAT_MIN;
}
This maybe is not an elegant solution but works for me
Swift version:
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return CGFloat.leastNormalMagnitude
}
override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return CGFloat.leastNormalMagnitude
}
Solution for iOS 15:
if #available(iOS 15.0, *) {
tableView.sectionHeaderTopPadding = 0
}
To fix in a whole project:
if #available(iOS 15.0, *) {
UITableView.appearance().sectionHeaderTopPadding = 0
}
More details: Extra padding above table view headers in iOS 15
Note: This only applies to UITableView.Style.plain.
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,
[self performSelector:#selector(updateDelegate) withObject:nil afterDelay:0.0];
there will be an extra 35 px space at the top. If line 27 is active and 24 is commented out,
self.tableView.delegate = self;
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.
Uncheck "Adjust Scroll View insets"
Another quick comment... even in XCode 6.1, there is a bug with vertical spaces appearing at the top of UIScrollViews, UITextViews and UITableViews.
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.)
While using grouped TableView use this to avoid border cutting in viewWillAppear
self.tableView.contentInset = UIEdgeInsetsMake(-35, 0, 0, 0);
According to this transition guide for iOS7 by Apple, the scroll view’s content insets is automatically adjusted.
The default value of automaticallyAdjustsScrollViewInsets is set to YES.
The UIViewController which has the UITableView should set this property to NO.
self.automaticallyAdjustsScrollViewInsets = NO;
This will do the trick.
EDIT 1:
Also, one could try -
self.navigationController.navigationBar.translucent = YES;
This also removes the extra padding on the top.
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:
// Replace UIView with whatever class you're using as your header below:
UIView *tableViewHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.tableView.bounds.size.width, CGFLOAT_MIN)];
self.tableView.tableHeaderView = tableViewHeaderView;
Something like this would lead to the issue at some point (typically, after a scroll):
// Replace UIView with whatever class you're using as your header below:
UIView *tableViewHeaderView = [[UIView alloc] initWithFrame:CGRectZero];
self.tableView.tableHeaderView = tableViewHeaderView;
Storyboard:
Just uncheck: Adjust Scroll View Insets in View Controller's options
Code:
self.automaticallyAdjustsScrollViewInsets = false
This is the solution for iOS 10 using Swift 3:
You can get rid of top and bottom paddings by implementing the following methods from the UITableViewDelegate.
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat
{
return CGFloat.leastNormalMagnitude
}
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat
{
return CGFloat.leastNormalMagnitude
}
This code worked for me, The best answer for me that was written in objective-C at up-side so I converted it into Swift.
For Swift 4.0+
self.tableView.tableHeaderView = UIView(frame: CGRect(x: 0, y: 0, width: self.tableView.bounds.size.width, height: .leastNonzeroMagnitude))
Just write this into viewDidLoad() and it will work like a charm.
For iOS 15+, above one won't work, so use this:-
if #available(iOS 15.0, *) {
tableView.sectionHeaderTopPadding = 0
}
For iOS 15+, if you want to apply change for your whole project, so use this:-
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
if #available(iOS 15.0, *) {
UITableView.appearance().sectionHeaderTopPadding = 0.0
}
}
So I was trying every method here, and this time none of them helped. My case was a grouped table view on iOS 9. I don't really know why and how I found out this one, but for me, setting the tableViewHeader with a UIView with at least 0.01 height worked out. CGRectZero didn't help, nothing really helped:
tableView.tableHeaderView = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 0.0, height: 0.01))
Simply add the following to your viewDidLoad in your VC:
self.automaticallyAdjustsScrollViewInsets = NO;
In my case this was what helped me. I'm supporting ios6 also.
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
self.edgesForExtendedLayout = UIRectEdgeNone;
self.extendedLayoutIncludesOpaqueBars = NO;
self.automaticallyAdjustsScrollViewInsets = NO;
}
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
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 :
self.automaticallyAdjustsScrollViewInsets = false
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.
To be specific, to remove tableviewHeader space from top i made these changes:
YouStoryboard.storyboard > YouViewController > Select TableView > Size inspector > Content insets - Set it to never.
Thanks to the answer by #Aurelien Porte. Here is my solution
Cause of this 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.
In ViewDidLoad:-
self.edgesForExtendedLayout = UIRectEdge.None
self.automaticallyAdjustsScrollViewInsets = false
No Need For Something Like This :-
self.myTableview.contentInset = UIEdgeInsetsMake(-56, 0, 0, 0)
In heightForHeaderInSection delegate:-
if section == 0
{
return 1
}
else
{
return 40; // your other headers height value
}
In viewForHeaderInSection delegate :-
if section == 0
{
// Note CGFloat.min for swift
// For Objective-c CGFLOAT_MIN
let headerView = UIView.init(frame: CGRectMake(0.0, 0.0, self.myShaadiTableview.bounds.size.width, CGFloat.min))
return headerView
}
else
{
// Construct your other headers here
}
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 the subviews of the UITableView 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):
- (void)listSubviewsOfView:(UIView *)view {
// Get the subviews of the view
NSArray *subviews = [view subviews];
// Return if there are no subviews
if ([subviews count] == 0) return;
for (UIView *subview in subviews) {
NSLog(#"%#", subview);
// List the subviews of subview
[self listSubviewsOfView:subview];
}
}
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
self.navigationController.navigationBar.translucent = YES;
framework will automatically set pre-calculated contentInset.
To avoid this you can do
self.automaticallyAdjustsScrollViewInsets = NO;
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
The only thing that worked for me was:
Swift:
tableView.sectionHeaderHeight = 0
tableView.sectionFooterHeight = 0
Objective-C:
self.tableView.sectionHeaderHeight = 0;
self.tableView.sectionFooterHeight = 0;
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:
self.tableView.tableHeaderView = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.size.width, height: 0.01))
Swift 4 code:
For tableview with no section headers you can add this code:
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return CGFloat.leastNormalMagnitude
}
and you will get the header spacing to 0.
If you want a header of your specific height pass that value:
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return header_height
}
and the view from viewForHeaderinSection delegate.
2022 answer:
You just do this
tableView.contentInsetAdjustmentBehavior = .never
which is undocumented
Bizarre subtle gotchya ->
Tableviews have a very strange behavior these days:
On devices with a notch (XR, etc) it will without telling you add more inset BUT ONLY IF the table starts at the physical top of the screen.
If you start NOT at the top of the screen, it won't do that, but
Both of those cases are >> unrelated << to safeAreaInsets ....... which is very confusing
All of that is totally undocumented ... you can waste hours figuring this out.
If you do need your measurements to start actually from the top of the screen/table,
in fact simply go:
tableView.contentInsetAdjustmentBehavior = .never
A good example is obviously when you add some sort of banner or similar thing over the top of a table, which is common these days, and you just set the top inset of the table to whatever height your banner/etc becomes when it's running.
To do that, you must use the
tableView.contentInsetAdjustmentBehavior = .never
call :/
Bonus gotchya
Don't forget that almost always these days, you're loading some information (user pictures, description, whatever) dynamically, so you can't set such values to the final needed value until the info arrives. Another gotchya. :/
So you'd have code like:
func setTableOffsetOnceFlagAreaSizeIsKnown() {
tableView.contentInset.top = yourSpecialFlagViewUpTop.bounds.height
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
setTableOffsetOnceFlagAreaSizeIsKnown()
}
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.
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.