Only one headerView is displayed


#1

I do not know why only one headerView is displayed . This is my code:

[code]- (UIView *)tableView:(UITableView *)tableView
viewForHeaderInSection:(NSInteger)section
{
if (section == 0) {
return [self headerView];
}

else 
{
    return [self headerView];
}

}

  • (CGFloat)tableView:(UITableView *)tableView
    heightForHeaderInSection:(NSInteger)section
    {
    if (section == 0 ) {
    return [[self headerView] bounds ].size.height;
    }
    else
    {
    return [[self headerView] bounds ].size.height;
    }

}[/code]


#2

I have same promble, no headerView in section 0,
and when I scroll tableview down and up several times,
this headerView in section 1 will disapper.
Thanks for any advice.


#3

As this implementation is outside the scope of the current chapter, I can only give suggestions based upon some documentation research that I came across from the previous chapter, but never really tested myself.

UITableView class has a method “headerViewForSection” make sure you have this properly implemented.

Since both posters seem to want to utilize the same headers for both sections, you may need to utilize the class UITableViewHeaderFooterView to set it up for reuse.

  • From the documentation it seems like you would have to link contentView to the XIB or maybe to headerView in the current implementation might be fine.
  • You may need to somehow utilize dequeueReusableHeaderFooterViewWithIdentifier in order for it to redisplay properly.