'why extra space is at top of UITableView - simple
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



Solution 1:[1]
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)];
Solution 2:[2]
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
Solution 3:[3]
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.
Solution 4:[4]
In Swift, you just need to set the below property to false.
self.automaticallyAdjustsScrollViewInsets = false
Solution 5:[5]
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.
Solution 6:[6]
Swift :
override func viewWillAppear(animated: Bool) {
self.edgesForExtendedLayout = UIRectEdge.None
OR
self.moduleListTableView.contentInset = UIEdgeInsetsMake(-64, 0, 0, 0);
OR
self.automaticallyAdjustsScrollViewInsets = false
}
Solution 7:[7]
try this....
self.tableView.contentInset = UIEdgeInsetsMake( 20, 20 , 0, 0)
Solution 8:[8]
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
}
Solution 9:[9]
This is how it can be fixed easily through Storyboard:
Select Table View > Size Inspector > Content Insets: Never
Solution 10:[10]
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
}
Solution 11:[11]
Maybe you have more than one parent navigation controller? If that's the case, uncheck other parent navigation controllers' "Show Navigation Bar".
Solution 12:[12]
This worked for me in swift:
tableView.tableHeaderView = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: CGFloat.leastNormalMagnitude))
Solution 13:[13]
For iOS 15.0+,
use this for removing extra padding at the top
if #available(iOS 15.0, *){
self.tableView.sectionHeaderTopPadding = 0.0
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow


