如何显示从xib加载的表? (MacOSx) [英] How show sheet loaded from xib? (MacOSx)
问题描述
我有一个xib文件,只有一个NSPanel在其中,我试图显示这个面板作为模式表(与 beginSheet:modalForWindow:modalDelegate:didEndSelector:contextInfo:
)。这个xib文件的所有者是一个控制器类MyController,它有NSPanel的IBOutlet。
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.
我正在寻找的是:
...
MyController *controller = [[MyController alloc] init];
[NSApp beginSheet:controller.panel modalForWindow:[NSApp mainWindow] modalDelegate:controller didEndSelector:nil contextInfo:nil];
...
问题:
必须MyController继承自 NSWindowController
或 NSObject
?.我尝试了 NSWindowController
和 initWithWindowNibName:
但出口到 NSPanel
Question:
Must MyController inherit from NSWindowController
or NSObject
?. I tried NSWindowController
and initWithWindowNibName:
but the outlet to NSPanel
always is nil.
感谢
推荐答案
您必须停用您用于工作表的窗口对象(在IB中)的几乎所有属性。我添加以下方法到我的控制器以显示工作表:
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
IBOutlet到工作表窗口。
panelSheet
is an IBOutlet to the sheet window.
感谢Jon Hess和JWWalker的帮助
Thanks Jon Hess and JWWalker for your help
这篇关于如何显示从xib加载的表? (MacOSx)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!