我正在运行一个自定义 NSWindowController 作为模式窗口。
首先,我这样展示它:
ProgressWindow *pWin = [[ProgressWindow alloc] initWithWindowNibName:@"ProgressWindow" andXmlContent:nil];
[NSApp runModalForWindow:[pWin window]];
然后我想从 ProgressWindow 的 NSWindowController 中解除它。为此,我在 windowDidLoad 函数中设置了以下代码(只是为了测试):
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:2]];
[self testMethod];
正如预期的那样,它在 2 秒后调用 testMethod 方法应该关闭模态窗口,但我似乎没有找到方法。我试过[NSApp stopModal]
, [NSApp abortModal]
, [self close]
, 把它做成一张纸然后打电话[self.window orderOut:nil];[NSApp endSheet:self.window];
,但似乎没有任何效果。要么什么都没有发生,要么窗口在另一个位置重新打开。我不知道为什么会这样,初始化代码只被调用一次。
谁知道怎么关闭???