I have a UITableView in the grouped style, and only one section. However there is some blank space above and below the table view that is shown when the user scrolls too far. How can I remove this blank space?
9 Answers
You can do this by altering the contentInset
property that the table view inherits from UIScrollView
.
self.tableView.contentInset = UIEdgeInsetsMake(-20, 0, -20, 0);
This will make the top and bottom touch the edge.

- 44,595
- 12
- 101
- 105
-
Thanks for the answer but It's actually not the bounce I'm talking about. What I want to try to remove is the about 10px-20px that are between the top of the table view and the first cell that is displayed, and the same for the footer. – Christian Gossain Jun 17 '11 at 03:23
-
Thanks that's a much more elegant solution. It turns out 30 px was that amount I needed. – Christian Gossain Jun 17 '11 at 21:42
-
Thank you so much. This is a common problem that I wasn't able to solve! – Eduardo Coelho Sep 27 '12 at 17:57
-
If you have a table header view this removes the space from the top of the table header view, obstructing part of it. – shim Jul 23 '13 at 18:15
-
5I guess the actual offsets for top and bottom may change depending on the OS and situation... I had to use self.tableView.contentInset = UIEdgeInsetsMake(-35, 0, -35, 0); to achieve the correct behavior. -rrh – Richie Hyatt Mar 27 '14 at 18:16
-
U saved my time. – Coder ACJHP Jul 27 '18 at 11:32
Add this code:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 0;
}

- 5,073
- 4
- 35
- 46
UIView can be inserted at the top and bottom of the table(drag and drop). Set their properties as transparent and height of 1 px. This is to remove the extra padding in front of the cells.

- 9,074
- 2
- 15
- 13
you can also use this code for removing space between first cell of uitableview..
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 0.002f;// set this...
}

- 1,479
- 16
- 25
This answer comes quite late, but I hope it helps someone.
The space is there because of the UITableView
's tableHeaderView
property. When the the tableHeaderView
property is nil
Apple defaults a view. So the way around this is to create an empty view with a height greater than 0
. Setting this overrides the default view thereby removing the unwanted space.
This can be done in a Storyboard by dragging a view to the top of a tableView
and then setting the height of the view to a value of 1
or greater.
Or it can be done programmatically with the following code:
Objective-C:
CGRect frame = CGRectZero;
frame.size.height = CGFLOAT_MIN;
[self.tableView setTableHeaderView:[[UIView alloc] initWithFrame:frame]];
Swift:
var frame = CGRect.zero
frame.size.height = .leastNormalMagnitude
tableView.tableHeaderView = UIView(frame: frame)
Comments
As others have noted you can use this same solution for footers.
Sources and Acknowledgements
See the Documentation for more details on the tableHeaderView
property.
Thanks to @liushuaikobe for verifying using the least positive normal number works.
My original answer: https://stackoverflow.com/a/22185534/2789144

- 1,793
- 1
- 20
- 25
In my case issue was with the constraints i was applying. I have to change them in order to show 2 rows in my case while bottom of table touching last row.

- 1,222
- 18
- 21
Use the bounces
property of UIScrollView
:
[yourTableView setBounces:NO];
This will remove what seems to be an extra padding at the top and bottom of your UITableView
.
Actually, it will just disable the tableview's scrollview to scroll past the edge of the content.

- 2,764
- 1
- 28
- 21