How to place a window in a separate NIB, provide its own NSWindowController, make it slide in the form of a sheet?
(Is this a typical thing that is related to 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. I think I'm trying to make it standard, but I cannot find clear examples or explanations of how to do what I want.
What I'm trying to do:
- My application delegate has a main window in which there is a button to open the settings sheet.
- Settings sheet:
- located in a separate NIB.
- has the owner of the file installed in the SettingsWindowController class, which is a subclass of NSWindowsController
- When the user clicks "settings", I try to use Apple [sample code] [1]
- (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 simplified and numerous questions:
- When I call
loadNibName:owner: I don’t want the owner be self , because it makes my application delegate the owner to “MyCustomSheet” - that what my SettingsWindowsController should be for, However, I don’t know how to make SettingsWindowsController owner in this method. - If “Visible at startup” is marked on my sheet, then
loadNibName:owner: immediately displays the window as a regular window, and not as a sheet that leaves the main window. - If my sheet does not display "Visible at launch", then
beginSheet:modalForWindow:etc calls "Modal session requires a modal window." I am sure this happened because I made the owner of Nib self (as already mentioned). - In the code example, I don’t know how the Nib named @ "SettingsSheet" is associated with the
settingsSheet instance variable - but they are apparently related because the code is checked first: if (!settingsSheet) (I've noted this with a comment //BUT HOW DOES THIS MAKE settingsSheet NOT nil? )
Thank you for your patience in reading all of this!
stifin
source share