Hi all,
My problem is that I can't get NSPopUpButtonCells to appear correctly
within an NSTableHeaderView. I'm trying to put popup buttons in my
column headers. I click on the header, and the mouseDown event fires in
my class which I subclassed from NSTableHeaderView, but the menu
doesn't popup so that I can select a new column header. I'm not really
sure what I need to be doing in the mouseDown event though (I was told
I needed to subclass my NSTableHeaderView to make it work, but still no
go, although I do get a mouseDown event now).
Another problem is that I have four columns and four headers of which I
can confirm in my code, but there are 5 headers that appear (the fourth
is shown twice as if it's not being redrawn).
Using IB, I have an NSTableView inside an NSScrollView and w/ the
inspector I have '0 Columns' (because I build the columns
programatically) and 'Column Headers Displayed' is checked.
Anyone have any ideas as to why my table headers are not working? I
can't see what's wrong, or really just don't understand what else I
need to be doing to make this work.
This is my table controller ...
Code:
- (void) awakeFromNib
{
NSTableHeaderView *currentTableHeader = [tableView headerView];
DataTableHeader *dataTableHeader = [[DataTableHeader alloc] init];
[dataTableHeader setFrame:[currentTableHeader frame]];
[dataTableHeader setBounds:[currentTableHeader bounds]];
[tableView setHeaderView:dataTableHeader];
}
Here I build the columns ...
Code:
NSTableColumn *column;
NSPopUpButtonCell *headerCell;
...
headerCell = [[NSPopUpButtonCell alloc] initTextCell:col];
[headerCell setControlSize:NSMiniControlSize];
[headerCell setBordered:NO];
[headerCell setEditable:YES];
[headerCell setPullsDown:NO];
[headerCell setFont:[NSFont labelFontOfSize:
[NSFont systemFontSize]]];
[headerCell addItemWithTitle:@"itemA"];
[headerCell addItemWithTitle:@"itemB"];
[headerCell addItemWithTitle:@"itemC"];
column = [[NSTableColumn alloc]
initWithIdentifier:[NSNumber numberWithInt:i]];
[column setHeaderCell:headerCell];
[column sizeToFit];
[tableView addTableColumn:column];
...
I subclassed NSTableHeaderView w/ my new class but don't really know
what else I should be doing here.
Code:
@interface DataTableHeader : NSTableHeaderView
{ }
- (void)mouseDown:(NSEvent *)theEvent;
@end
@implementation DataTableHeader
- (void)mouseDown:(NSEvent *)theEvent
{
NSLog(@"mouseDown event");
[self setNeedsDisplay:YES];
}
Thanks,