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

发布于 2024-10-01 00:06:37 字数 639 浏览 1 评论 0原文

我有一个 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 必须继承自 NSWindowControllerNSObject 吗?我尝试了 NSWindowControllerinitWithWindowNibName:NSPanel 的出口始终为零。

谢谢

I have a xib file with only an NSPanel in it, I'm trying to show this panel as modal sheet (with beginSheet:modalForWindow:modalDelegate:didEndSelector:contextInfo:). The file's owner for this xib is a controller class "MyController" which has the IBOutlet to the NSPanel.

What I am looking for is something like:

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

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

Question:
Must MyController inherit from NSWindowController or NSObject?. I tried NSWindowController and initWithWindowNibName: but the outlet to NSPanel always is nil.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼泪淡了忧伤 2024-10-08 00:06:37

我解决了。您必须停用用于工作表的窗口对象(在 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 的帮助

I resolve it. You must deactivate almost all the properties of the window object (in the IB) that you are using for the sheet. I add the following method to my controller to show the sheet:

- (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 is an IBOutlet to the sheet window.

Thanks Jon Hess and JWWalker for your help

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文