1

When a section in a grouped UITableView contains both header text and footer text, the spacing between that section and one above it becomes inconsistent with the rest of the table view.

To make sure this wasn't developer error (or an Xcode project upgrade issue) I added a new UITableViewController to my project and set it to Style > Grouped. I then added three sections, each containing header text. In the last section I added footer text. All heights are set to their default values.

As you can see in the linked example, the distance between Section 1 and Section 2 is 168px. However the distance between Section 2 and Section 3 is 190px. If I remove the footer text in Section 3, this closes up to the correct 168px so having footer text in Section 3 is somehow causing this spacing issue between sections.

This layout was built entirely in the Storyboard. I've also tried building it from code (including setting header/foot height manually) and the same issue occurs.

Any ideas?

Jason Cox
  • 26
  • 3

1 Answers1

0

There doesn't appear to be a way to fix this with Storyboards alone. So far the best solution I've found is to manually set the height of the headers using tableView:heightForHeaderInSection:.

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    //Retreive the title for this section
    NSString *stringTitleForSection = [self tableView:tableView titleForHeaderInSection:section];

    //Check to see which height should be used
    if (section == 0 && stringTitleForSection != nil)
    {
        return 55.333333f;
    }
    else if (stringTitleForSection != nil)
    {
        return 38.0f;
    }
    else
    {
        return 0.0f;
    }
}

The default height values can be retrieved by using the below code on a virgin UITableView; I believe these have only changed once or twice over the history of iOS.

NSLog(@"Section 0: %f", [self.tableView headerViewForSection:0].frame.size.height);
Jason Cox
  • 26
  • 3