Search code examples
headeruitableviewios7

Header views height for grouped UITableView on iOS7


I'm building my settings screen and using a grouped table view. When trying to set the headers I see spacing above my header view. I double checked and I do pass the correct view height in -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section.

Here is a screenshot of this behavior: enter image description here

You can see my view with the title (VIBRATE, SILENT MODE) in it and it's darker bg color and the brighter space above it.


Solution

  • After much searching, I have finally found a fix for this. The tableview's delegate needs to implement heightForFooterInSection and return a very small number. Returning 0 defaults to the same spacing that was causing the extra spaces.

    -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
        return CGFLOAT_MIN;
    }