4

我有一个 xib 文件,其中只有一个 NSPanel,我试图将此面板显示为模式表(带有beginSheet:modalForWindow:modalDelegate:didEndSelector:contextInfo:)。此 xib 的文件所有者是一个控制器类“MyController”,它具有到 NSPanel 的 IBOutlet。

我正在寻找的是这样的:

...
MyController *controller = [[MyController alloc] init];

[NSApp beginSheet:controller.panel modalForWindow:[NSApp mainWindow] modalDelegate:controller didEndSelector:nil contextInfo:nil];
...

问题:MyController 必须继承自NSWindowControllerorNSObject吗?我试过了NSWindowControllerinitWithWindowNibName:但出口NSPanel总是为零。

谢谢

4

1 回答 1

8

我解决它。您必须停用您用于工作表的窗口对象(在 IB 中)的几乎所有属性。我将以下方法添加到我的控制器以显示工作表:

- (void)showInWindow:(NSWindow *)mainWindow {
    if (!panelSheet)
        [NSBundle loadNibNamed:@"XibName" owner:self];

    [NSApp beginSheet:panelSheet modalForWindow:mainWindow modalDelegate:nil didEndSelector:nil contextInfo:nil];
    [NSApp runModalForWindow:panelSheet];   //This call blocks the execution until [NSApp stopModal] is called
    [NSApp endSheet:panelSheet];
    [panelSheet orderOut:self];
}

panelSheet是工作表窗口的 IBOutlet。

感谢 Jon Hess 和 JWWalker 的帮助

于 2010-11-28T20:00:33.227 回答