Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MacRumoron

macrumors 6502
Original poster
Sep 6, 2005
324
0
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

macrumors 6502
Dec 6, 2006
277
1
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:mad: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

macrumors 6502
Original poster
Sep 6, 2005
324
0
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

macrumors 6502
Dec 6, 2006
277
1
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.
 

garethlewis2

macrumors 6502
Dec 6, 2006
277
1
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

macrumors G4
Nov 3, 2005
10,434
12,250
UK
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.