You need to use the method heightForHeaderInSection for defining the space between header & cell text. You can also change it depending on different sections for eg. at some sections you may need to show more distance & under some, you don't want to show gap. For such case you can use CGFLOAT_MIN which is 0.000001f. Giving you an example, how you can use different section with different header heights:
Along with the answer posted by Icaro I would like to add that you also need to implement the tableView:viewForFooterInSection: method returning nil for the section you want to remove the empty space below
It will then become:
As you see for viewForFooterInSection and viewForHeaderInSection I needed to return nil.
In case you only want to change the footerHeight, just return CGFloat.leastNormalMagnitude for heightForHeaderInSection, and return the heights for each section in heightForFooterInSection.
Select the tableView in your storyboard/objectCode and ensure that the style is set to Plain, instead of Grouped. You can find this setting in the attributes "Inspector" tab.
Rather than implementing the UITableViewDelegate methods and defining the sectionFooterHeight via CGFloat.leastNormalMagnitude, one can alternatively just
tableView.sectionFooterHeight = 0
and the spacing between sections while no footer is present will go away.
The mechanism is that by default this value is set to UITableView.automaticDimension.
As long as
it stays UITableView.automaticDimension
there are no delegate/dataSource methods that implement the configuration of footer i.e. titleForFooterInSection/viewForFooterInSection
table view's style is set to .grouped
then UITableView will deliberately insert a spacing between sections with no view.
You change sectionFooterHeight to 0, the magic goes away.