Re: Prevent Asynchronous operation of beginSheetModalForWindow
Re: Prevent Asynchronous operation of beginSheetModalForWindow
- Subject: Re: Prevent Asynchronous operation of beginSheetModalForWindow
- From: "John Love" <email@hidden>
- Date: Mon, 16 Jun 2008 13:51:25 -0400
Hello, Graham ...
Because I have multiple calls to show a sheet, from various parts of my
FileController, and because I wanted to make my sheet calls as general as
possible, I really .. really .. wanted to have a distinct SheetController.
As a result, I made calls from FileController to look like:[theSheet
showSheet:itsWindow], where theSheet was an outlet of FileController.
I could get away with that since all my sheets had just one button .. except
one, which had 3 buttons .. and for that exception, the asynchronous nature
of sheets got in the away.
I have not given up on a separate SheetController .. however .. I finally
reduced my showSheet routine to something very, very short and placed it in
FileController ..
- (void) showSheet: (NSWindow*)theSheet
forWindow:(NSWindow*)theWindow
withDescription:(NSString*)theDescription {
if (theDescription) {
if (theSheet == calculateSheet) {
if (calculateDescription) // NSTextField outlets of
FileController, 1 per sheet
[calculateDescription setStringValue:theDescription];
}
else if (theSheet == saveSheet) {
if (saveDescription)
[saveDescription setStringValue:theDescription];
}
else if (theSheet == errorSheet) {
if (saveDescription)
[saveDescription setStringValue:theDescription];
}
}
[NSApp beginSheet:theSheet
modalForWindow:theWindow
modalDelegate:nil
didEndSelector:nil //
@selector(sheetDidEnd:returnCode:contextInfo:)
contextInfo:nil];
itsReturnCode = [NSApp runModalForWindow:theSheet]; // (int)
itsReturnCode in FileController.h
[NSApp endSheet:theSheet];
[theSheet orderOut:self];
}
When I called showSheet, it looked like:
[self showSheet:calculateSheet forWindow:itsWindow
withDescription:nil]where calculateSheet, showSheet and errorSheet were 3
IBOutlets of FileController, all of class = NSWindow.
Every button of each sheet was connected to a specific IBAction of
FileController, e.g.,
- (IBAction) dontSaveIt:(id)sender {
[self closeSheetWithCode:doCloseDoc];
}
with that last message looking like:
- (void) closeSheetWithCode:(int)theCode {
[NSApp stopModalWithCode:theCode];
}
As the docs explain, when you do that, the message [NSApp
runModalForWindow:] returns that identical integer, which can be any integer
of your choosing. In my case, the integer choices trigger a decision
whether to close the mainWindow after the sheet is closed, or whether to
keep mainWindow open after the sheet is closed.
I did not even have to mess with sheetDidEnd selectors because
closeSheetWithCode returned gave the needed flag I could use to quantify the
itsReturnCode instance variable of FileController.
Anyway, I have sheets, not the relatively antequated separate dialogs.
I have no intention of giving up on a separate SheetController .. but, in
the meantime, I have something that works.
Best regards,
John Love
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden