Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom table header section

I got an app with group style table.

I tried to customize table header section:

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)];
    UILabel *userName = [[UILabel alloc] initWithFrame:CGRectMake (0,0,200,30)];
    if (section != 0)userName.text = @"lalala";
    [userName setFont:[UIFont fontWithName:@"HelveticaNeue" size:20]];
    [headerView addSubview:userName];
    [headerView setBackgroundColor:[UIColor clearColor]];
    [userName setBackgroundColor:[UIColor clearColor]];
    return headerView;
}

But my headers close cells:

enter image description here

Why?

like image 732
Eugene Trapeznikov Avatar asked Nov 30 '22 15:11

Eugene Trapeznikov


2 Answers

You also need to implement tableView:heightForHeaderInSection: to set the correct height for the section header. See the Apple docs

like image 167
Ian L Avatar answered Dec 21 '22 20:12

Ian L


This is happening because the height of your header is set to 0 until you override the other delegate:

– tableView:heightForHeaderInSection:

like image 32
Cthutu Avatar answered Dec 21 '22 20:12

Cthutu