gpt4 book ai didi

objective-c - NSClosableWindowMask 对话框行为异常

转载 作者:太空狗 更新时间:2023-10-30 03:45:30 26 4
gpt4 key购买 nike

我有一个 Safari 浏览器插件,我想在其中打开一个 NSWindow 来显示版权说明。虽然对话框中的“确定”按钮关闭了对话框的窗口,并且运行良好,但当我单击左上角的红色关闭窗口“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];
}

最佳答案

我已经修改了您的代码,尝试如下所示:-

- (void) closeBox
{
// called when the Ok button pressed
//Commented this line
// [NSApp abortModal];

[mwin performClose:mwin];// Modified this line


}

//Modified below notification just comment the parameter
- (void)closeClicked/*:(NSNotification *)notification*/
{

[NSApp abortModal];

}


- (void) openBox
{
NSRect frame = NSMakeRect(0, 0, 300, 250);
mwin = [[[[NSWindow alloc] initWithContentRect:frame
styleMask:NSClosableWindowMask |NSTitledWindowMask
backing:NSBackingStoreBuffered
defer:NO]retain]autorelease];
//Modified notification below

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(closeClicked)
name:NSWindowWillCloseNotification
object:nil];
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 - NSClosableWindowMask 对话框行为异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20491913/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com