iPhone When increasing the height of UITableView section header the height of the cell below it decreases. How to avoid?

StackOverflow https://stackoverflow.com/questions/13659718

Pergunta

I created a UITableView of which I adjusted the height and background of the section header. This all works as expected but the cell (row) below it becomes smaller. It almost seems that the section header goes over the first cell. Is there a way to solve this? Or should I ask, how to solve this?

My code of the section header:

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)];

    UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, tableView.bounds.size.width, 30)];
    headerLabel.text = [self tableView:tableView titleForHeaderInSection:section];
    headerLabel.font = [UIFont boldSystemFontOfSize:16];
    [headerLabel setTextColor:[UIColor whiteColor]];
    headerLabel.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"menuSectionBg.png"]];

    [headerView addSubview:headerLabel];

    return headerView;
}
Foi útil?

Solução

You should not adjust the height of the cells' views, but instead implement the

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;

method in your UITableViewDelegate implementation.

The heights for the cells are calculated before the cells are even created.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top