【发布时间】:2013-12-10 10:26:40
【问题描述】:
我有一个 Safari 浏览器插件,我想在其中打开一个 NSWindow 来显示版权说明。虽然对话框中的 Ok 按钮关闭了对话框的窗口,并且工作正常,但当我单击左上角的红色关闭窗口“x”时,它也会关闭窗口,但它是父窗口(整个浏览器选项卡,我已在其中运行插件),仍然处于禁用状态,就好像在某处仍然打开了一个模态窗口。
我什至尝试将一个新的选择器附加到窗口关闭通知,它运行与确定按钮相同的代码,但仍然无法正常工作。
以下是代码的相关部分:
- (void) closeBox
{
// called when the Ok button pressed
[NSApp abortModal];
}
- (void)closeClicked:(NSNotification *)notification
{
// called when the close window 'x' button pressed
NSLog(@"Closed");
[NSApp abortModal];
}
- (void) openBox
{
NSRect frame = NSMakeRect(0, 0, 300, 250);
mwin = [[[NSWindow alloc] initWithContentRect:frame
styleMask:NSClosableWindowMask |NSTitledWindowMask
backing:NSBackingStoreBuffered
defer:NO] autorelease];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(closeClicked:)
name:NSWindowWillCloseNotification
object:mwin];
NSButton * bn;
bn = [[[NSButton alloc] initWithFrame:NSMakeRect(10, 10, 100, 20) ] autorelease];
[bn setButtonType:NSMomentaryPushInButton];
[bn setTitle:@"Ok"];
[bn setTarget:self];
[bn setAction:@selector(closeBox)];
[[mwin contentView] addSubview:bn];
[NSApp runModalForWindow:mwin];
}
【问题讨论】:
标签: objective-c macos nswindow