Reputation: 5086
I have 2 sections in my UITableView. I'd like my first header to be nonexistant, no space, no nothing. The first cell touches the top of the screen. I'd like a custom section header for my second section.
I can do this if I don't use - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
but the moment I use this method a blank header view appears in the first section. What am I doing wrong?
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
if (!section == 0){
UIView *header = [[UIView alloc]initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30.0f)];
UILabel *label = [[UILabel alloc]initWithFrame:[header frame]];
[label setText:@"Test Header"];
[header addSubview:label];
return header;
}
else{
// This apparently causes a header to appear in section 0.
// Without this entire method it works fine- but it means I can't customize
// the header.
return nil;
}
}
Upvotes: 1
Views: 3553
Reputation: 1621
Look for the
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
method of UITableView
.
You can return 0;
for the first section.
Upvotes: 6
Reputation: 1120
Use this,
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if (section == 0){
return 0;
}
//...
}
Upvotes: 1