Reputation: 1110
In some OS X apps, control-clicking on the header of an NSTableView brings up a context menu, that lets the user choose which columns are visible.
Is this something I'll need to implement manually, or is this some hard to find Cocoa feature?
Upvotes: 0
Views: 220
Reputation: 1072
AFAIK, it isn't a standard feature of NSTableView. You have to implement it on your own by setting the menu of NSTableHeaderView.
NSMenu *menu = [[NSMenu alloc] initWithTitle:@""];
menu.font = [NSFont menuFontOfSize:[NSFont smallSystemFontSize]];
menu.showsStateColumn = YES;
for (NSTableColumn *column in tableView.tableColumns) {
NSMenuItem *item = [menu addItemWithTitle:column.headerToolTip action:@selector(toggleTableColumn:) keyEquivalent:@""];
item.state = [column isHidden] ? NSOffState : NSOnState;
item.representedObject = column;
}
tableView.headerView.menu = menu;
Upvotes: 2