gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 16:13:04 24 4
gpt4 key购买 nike

我有一个 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/

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