カスタム NSCell サブクラス IconCell を含む NSTableView があります。
IconCell には、画像、テキスト、ボタンの 3 つの要素が含まれています。
これが私の描画コードの簡略版です(closeButton
はボタンです):
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
NSPoint cellPoint = cellFrame.origin;
[controlView lockFocus];
CGFloat buttonWidth = [closeButton frame].size.width;
[someNSImage drawInRect:NSMakeRect(cellPoint.x, cellPoint.y, ICON_WIDTH, ICON_HEIGHT) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0 respectFlipped:YES hints:nil];
[someNSString drawInRect:NSMakeRect(cellPoint.x+ICON_WIDTH+PADDING, cellPoint.y, cellFrame.size.width - ICON_WIDTH - buttonWidth, cellFrame.size.height) withAttributes:someTextAttributes];
[(NSButtonCell*)[closeButton cell] drawWithFrame:NSMakeRect(cellPoint.x + cellFrame.size.width - buttonWidth, cellPoint.y, buttonWidth, cellFrame.size.height) inView:controlView];
[controlView unlockFocus];
}
描画部分は正常に動作し、次のようなものが生成されます。
それが私が欲しいものです。
さらに、ユーザーがセルを操作したときに、次の 2 つのいずれかが発生するようにしたいと考えていますactionA
。ユーザーが閉じるボタンをクリックすると、それが行われますactionB
。
私が抱えている問題は、閉じるボタンが「見えない」ように見えることです-クリックしても動かず(動作中のボタンは押し下げられた状態を表示する必要があります)、一般的にはそうであるかのように動作しますのactionA
代わりにトリガーされactionB
ます。
これは私が2つのアクションを設定する方法です:
[tableView setAction:@selector(actionA)];
と
[closeButton setAction:@selector(actionB)];
私は何を間違っていますか?