views:

15

answers:

1

In my application I have an NSTableView with a custom header cell that is programatically assigned. The code to assign the custom cell looks like this:

-(void)setupTableHeader:(id)table {
 NSArray *columns = [table tableColumns];
    NSEnumerator *cols = [columns objectEnumerator];
    NSTableColumn *col = nil;

    TRDarkTableColumnHeaderCell *iHeaderCell;

    while (col = [cols nextObject]) {
        iHeaderCell = [[TRDarkTableColumnHeaderCell alloc] initTextCell:[[col headerCell] stringValue]];
        [col setHeaderCell:iHeaderCell];
        [iHeaderCell release];
    }
}

This works as you'd expect. However, when my window is resized and the NSTableView renders its scrollbars, an additional header cell is created with the default NSTableHeaderCell. To attempt to handle this, I tried to setup a notification to fire on window resize. Unfortunately, this has no effect (my setupTableHeader function still returns 1 column for the table)

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setupTableHeaders) name:NSWindowDidResizeNotification object:[[NSApp delegate] window]];

Note that my notification calls a helper function setupTableHeaders, which calls the setupTableHeader function mentioned above. Here's a screenshot to illustrate the issue:

alt text

A: 

This is the corner view. Try:

[table setCornerView:nil];

You may also have to replace the table's header view with a custom subclass that draws the same background if your column resizing allows the total width of all columns to be less than the width of the table (exposing a "blank" header area drawn by a default header cell).

Joshua Nozzi
As suggested, I had to subclass the table header view also, but this worked wonderfully. Thank you.
ndg