Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 973
Gal Avatar asked Aug 04 '13 14:08

Gal


People also ask

Why is there extra padding at the top of my UITableView?

Starting in iOS7, there is additional space at the top of my UITableView 's which have a style UITableViewStyleGrouped . The tableview starts at the first arrow, there are 35 pixels of unexplained padding, then the green header is a UIView returned by viewForHeaderInSection (where the section is 0).

How do you remove the blank space at the top of a grouped UITableView?

You can change the space between tableviewcells themselves by: [myTableView setSectionHeaderHeight:0]; [myTableView setSectionFooterHeight:25];


1 Answers

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;
}
like image 81
Casey Avatar answered Nov 01 '22 02:11

Casey