sti*_*fin 8 macos cocoa objective-c interface-builder cocoa-sheet
如何在单独的NIB中放置一个窗口,给它自己的NSWindowController,让它作为一张纸滑出?
(这是与床单有关的典型事吗?)
我试图从我的主窗口显示一个自定义工作表(从父窗口的标题栏向下滑动的窗口).我想,我想要做的就是标准,但是我找不到明确的例子或解释如何做到我想要的.
我想做什么:
- (void)showCustomSheet: (NSWindow *)window
// User has asked to see the custom display. Display it.
{
if (!settingsSheet)
//Check the settingsSheet instance variable to make sure the custom sheet does not already exist.
[NSBundle loadNibNamed:@"SettingsSheet" owner: self];
//BUT HOW DOES THIS MAKE settingsSheet NOT nil?
[NSApp beginSheet: settingsSheet
modalForWindow: window
modalDelegate: self
didEndSelector: @selector(didEndSheet:returnCode:contextInfo:)
contextInfo: nil];
// Sheet is up here.
// Return processing to the event loop
}
Run Code Online (Sandbox Code Playgroud)
请原谅以下简单而众多的问题:
loadNibName:owner:
,我不想owner
成为self
,因为这使我的应用程序委托"MyCustomSheet"的所有者 - 这就是我SettingsWindowsController
应该做的.但是,我不知道如何使SettingsWindowsController
这个方法的所有者.loadNibName:owner:
立即将窗口显示为普通窗口,而不是从主窗口滑出的工作表.beginSheet:modalForWindow:etc
导致"模态会话需要模态窗口".我很确定这是因为我制作了Nib的所有者self
(正如我已经提到过的).settingsSheet
- 但它们显然是相关的,因为代码首先检查:( if (!settingsSheet)
我用注释标记了这个//BUT HOW DOES THIS MAKE settingsSheet NOT nil?
)感谢您耐心阅读所有这些!
Gra*_*yer 10
创建一个实例SettingsWindowController
,使用initWithWindowNibName:
你不希望它在发布时可见.
见1.
您的实例变量可用于 SettingsWindowController