PDA

View Full Version : Help with sheets




MacRumoron
Mar 26, 2007, 08: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. :)



garethlewis2
Mar 27, 2007, 02:09 AM
You should have two methods.

One called something like
- (IBAction)openSheet:(id)sender;

Another called

- (IBAction)closeSheet:(id)sender;

And finally a callback method with the format

sheetDidEnd:something:somethingelsecontext;

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

[nameofsheetWindow orderOut:sender];

// 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.

MacRumoron
Mar 27, 2007, 11:30 PM
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.

garethlewis2
Mar 28, 2007, 01:46 AM
Okay,

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.

caveman_uk
Mar 28, 2007, 02:17 AM
Okay,

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.

garethlewis2
Mar 28, 2007, 04:00 AM
I thought they deprecated this with Tiger and Leopard. Did you code that on Jaguar or Panther?

garethlewis2
Mar 28, 2007, 04: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.

Eraserhead
Mar 28, 2007, 06: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