Reputation: 147
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;
}
Upvotes: 1
Views: 1227
Reputation: 32527
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.
Upvotes: 2