开发者

NSTableView with custom NSColumnHeaderCell

开发者 https://www.devze.com 2023-01-04 19:01 出处:网络
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:

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 w开发者_StackOverflow中文版indow 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 http://img22.imageshack.us/img22/640/headercell.png


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消