View Full Version : Help with sheets
Mar 26, 2007, 09:17 PM
I'm trying to open a sheet attached to a window, after choosing a file from an open panel which is attached to the same window.
I tried opening the sheet from the didEndSelector: of the open panel, but the code gets executed immediately when the Open button is pushed, and not when the open panel is finished closing. This is a problem because before the open panel finishes closing, the new sheet opens then for some reason the main window closes, and I am just left with a sheet that is attached to nothing (it is just a square box floating and can't be moved).
Any suggestions? Thanks in advance. :)
Mar 27, 2007, 03:09 AM
You should have two methods.
One called something like
And finally a callback method with the format
Your open button should call openSheet and execute the command
[NSApp beginSheet:nameofsheetwindow modalForWindow[NSApp mainwindow] modalDelegate:self didEndSelector:@selector(sheetDidEnd:blah:blahContext:) contextInfo:WHATEVER];
The close button on the sheet should be attached to the method closeSheet and should contain at least the following
// This returns event handling back to normal
[NSApp endSheet:nameofsheetWindow returnCode:1];
In the method starting with sheetDidEnd or whatever you want to call it, is where you retrieve the data from controls on the sheet.
Mar 28, 2007, 12:30 AM
I don't think you understood what I wrote. I am trying to open a sheet after the user chooses a file from an NSOpenPanel sheet. The problem is the sheet opens while the NSOpenPanel sheet is still open which for some reason causes the main window to close.
Mar 28, 2007, 02:46 AM
I don't believe you can open a sheet from within a sheet. I have never seen it and I doubt it would work. Since the sheet when started with begin sheet, has no window, you can't attach another sheet to it, as there is no parent to begin with. You could try and attach this subsheet to the main parent window, but more than likely this would cause the first sheet to close or OS X to behave very oddly.
Mar 28, 2007, 03:17 AM
I don't believe you can open a sheet from within a sheet. I have never seen it and I doubt it would work.
Yes you can because I've done it.
Mar 28, 2007, 05:00 AM
I thought they deprecated this with Tiger and Leopard. Did you code that on Jaguar or Panther?
Mar 28, 2007, 05:17 AM
Yep, your right it does work, just knocked up a simple example that opens a sheet within another sheet. Doesn't do anything fancy just opens and closes the sheets within a sheet, but since you still call the method
sheetDidEnd:returncode:contextinfo when you end the sheet I don't see how you couldn't get the data from it.
Mar 28, 2007, 07:38 AM
You may need to make a custom open panel to do what you want, rather than using
- (void)beginSheetForDirectory:(NSString *)absoluteDirectoryPath file:(NSString *)filename types:(NSArray *)fileTypes modalForWindow:(NSWindow *)docWindow modalDelegate:(id)modalDelegate didEndSelector:(SEL)didEndSelector contextInfo:(void *)contextInfo