プログラムで閉じるボタンを追加したいと思いNSWindow
ます。ボタンを表示することはできますが、マウスオーバーまたはマウスダウンの効果はありません。ボタンをクリックしても、「セレクター」が呼び出されないようです。何が問題なのか、なぜこれがそんなに面倒なのか、よくわかりません。
これが私がいじっているものです:
closeButton = [NSWindow standardWindowButton:NSWindowCloseButton forStyleMask:self.styleMask];
NSView *themeFrame = [[self contentView] superview];
NSRect c = [themeFrame frame]; // c for "container"
NSRect aV = [closeButton frame]; // aV for "accessory view"
NSRect newFrame = NSMakeRect( c.size.width - aV.size.width - 5, // x position c.size.height - aV.size.height - 5, // y position aV.size.width, // width aV.size.height); // height
[closeButton setFrame:newFrame];
[themeFrame addSubview:closeButton];
[closeButton setAutoresizingMask:NSViewMaxXMargin | NSViewMinYMargin];
[closeButton setEnabled:YES];
[closeButton setTarget:self];
[closeButton setAction:NSSelectorFromString(@"testClick:") ];
「testClick」は私のクラスの単なるメンバー関数であり、次のように定義されています。
- (void)testClick:(id)sender
問題は次の呼び出しのようです:
[themeFrame addSubview:closeButton];
themeFrame は次のとおりです。[[self contentView] superview]
ボタンを追加するだけで[self contentView]
機能しますが、タイトルバーに追加したいと思います。
Interface Builder を使用しないでください...