NSTableView 内の NSButtonCell を押しても row が選択されないようにする
- OS X 10.5.4
NSTableView のリファレンスを見るとそのものずばりの事が書いてある
tableView:shouldTrackCell:forTableColumn:row:
http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSTableView_Class/Reference/Reference.html
For example, this allows you to have an NSButtonCell in a table which does not change the selection, but can still be clicked on and tracked.
のだが、やり方がわからない。次のような NSTableView のサブクラスを作るといちおう期待通り動いた。
@interface MyTableView : NSTableView { BOOL selectionShouldChange; } @end @implementation MyTableView - (void)awakeFromNib { [self setDelegate:self]; selectionShouldChange = YES; } - (void)mouseDown:(NSEvent *)theEvent { NSUInteger column = [self columnAtPoint:[self convertPoint:[theEvent locationInWindow] fromView:nil]]; selectionShouldChange = (column != 0); // ボタンが 0 列目の場合 [super mouseDown:theEvent]; selectionShouldChange = YES; } - (BOOL)selectionShouldChangeInTableView:(NSTableView *)aTableView { return selectionShouldChange; } - (BOOL)tableView:(NSTableView *)tableView shouldTrackCell:(NSCell *)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row { return YES; } @end
tableView:shouldTrackCell:forTableColumn:row: は 10.5 以降