How do I put a window in a separate NIB, give it its own NSWindowController, make it slide out as a sheet?
(Is this a typical thing to do with sheets?)
I am trying to show a custom sheet (a window that slides down from the title bar of the parent window) from my main window. What I'm trying to do is standard, I think, but I cannot find clear examples or explanations for how to do exactly what I want.
What I am trying to do:
- (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
}
Please excuse the following simplistic and numerous questions:
loadNibName:owner:
, I don't want owner
to be self
, because that makes my app delegate the owner of the "MyCustomSheet" - that's what my SettingsWindowsController
is supposed to be for. However, I don't know how make SettingsWindowsController
the owner in this method.loadNibName:owner:
immediately displays the window as a normal window, not as a sheet that slides out from the main window.beginSheet:modalForWindow:etc
causes "Modal session requires modal window". I'm pretty sure this is because I made the Nib's owner self
(as I mentioned already).settingsSheet
- but they apparently are related because the code checks first: if (!settingsSheet)
(I've marked this with comment //BUT HOW DOES THIS MAKE settingsSheet NOT nil?
)Thanks for your patience in reading all this!
Create an instance of SettingsWindowController
, use initWithWindowNibName:
You don't want it visible at launch.
See 1.
Your instance variables will be available to SettingsWindowController