cocoa - 如何显示从 xib 加载的工作表? (MacOSx)

标签 cocoa macos nswindow nswindowcontroller

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

我正在寻找的是这样的:

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

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

问题: MyController 必须继承自 NSWindowControllerNSObject 吗?我尝试了 NSWindowControllerinitWithWindowNibName:NSPanel 的导出始终为零。

谢谢

最佳答案

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

- (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 的帮助

关于cocoa - 如何显示从 xib 加载的工作表? (MacOSx),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4107227/

相关文章:

ios - Cocoa dispatch_once 每个实例

objective-c - 带有 setBackgroundColor 的纹理 NSWindow 具有淡灰色背景

c++ - @executable_path 不工作

macos - 为 "always on top"行为切换 NSWindow 级别

cocoa - OSX El Capitan 上的透明 NSWindow

Cocoa - 以编程方式垂直拉伸(stretch) NSView,向下移动其后的所有内容

objective-c - 更改默认 insertTab : action in NSSearchfield

cocoa - Xcode 3.2 中缺少 "find options"

具有整数值的 cocoa slider

php - 如何在 MAMP 上显示错误?