views:

109

answers:

1

Hi, whenever I set my tableHeaderView I'm not seeing it in the Simulator. If I add it as a subview, it ends up getting drawn underneath the section header. Any idea what I'm missing here?

I do have a XIB file. I didn't see any properties in IB to affect headerViews though.

- (void)viewDidLoad {   
[super viewDidLoad];
MyTitleView *titleView = [[MyTitleView alloc] initWithFrame:CGRectMake(60,0,260,40)];
titleView.label.text = @"My Title";
self.navigationItem.titleView = titleView;
[titleView release];

StandardTableHeaderView *headerView = [[StandardTableHeaderView alloc] initWithFrame:CGRectMake(0,0,320,44)];
self.tableView.tableHeaderView = headerView;

// [self.view addSubview:self.tableView.tableHeaderView]; [headerView release];

NSLog(@"Header: %@",self.tableView.tableHeaderView); //Logs ] Header:     <StandardTableHeaderView: 0x5a508b0; frame = (0 0; 320 44); layer = <CALayer: 0x5a51130>>

Edit: StandardTableHeaderView.m init method:

- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
    self.backgroundColor = [UIColor redColor];
    self.label = [[UILabel alloc] initWithFrame:CGRectMake(frame.origin.x,0,frame.size.width,frame.size.height)];
    self.label.backgroundColor = [UIColor clearColor];
    self.label.textColor = [UIColor whiteColor];
    self.label.font = [UIFont fontWithName:@"Helvetica" size:16];
    [self addSubview:self.label];
}
return self;
}
A: 

First of all your code looks fine.

2 possible problems:

  • self.tableView is not set
  • tableHeaderView is overridden after viewDidLoad
Michael Kessler
My tableView is set -- cells are functioning fine and the log shows the tableHeaderView frame fine. I'm not changing the tableHeaderView anywhere else.. maybe some weirdness and should copy into a new project?
quantumpotato
For now I'll try resizing the tableview and adding the Header View as a separate view..
quantumpotato
How have you checked that the tableView property is set (not nil)? The fact that the cells are drawn doesn't necessarily say that the tableView property is not nil... try to add `NSLog(@"self.tableView = %@, self.tableView.tableHeaderView = %@", self.tableView, self.tableView.tableHeaderView);` right after the `self.tableView.tableHeaderView = headerView;` inside `viewDidLoad` and see what you get in the log...
Michael Kessler