circuitlego circuitlego - 2 years ago 264
iOS Question

How to change height of grouped UITableView header?

I know how to change the height of the section headers in the table view. But I am unable to find any solution to change the default spacing before the first section.

Right now I have this code:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
if (section == 0){
return 0;
return 10;

enter image description here

Answer Source

It appears that I can't set a table header view with height of 0. I ended up doing the following:

- (void)viewWillAppear:(BOOL)animated{
    CGRect frame = self.tableView.tableHeaderView.frame;
    frame.size.height = 1;
    UIView *headerView = [[UIView alloc] initWithFrame:frame];
    [self.tableView setTableHeaderView:headerView];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download