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: Thu, 19 Jun 2008 12:11:15 -0400
Completed the housekeeping I needed to do .. so I began moving all the sheet
code over to SheetController.
Within FileController, I have 3 IBOutlets which are the 3 different sheet
NSWindow's *and* the same 3 sheet NSWindow outlets for SheetController. I
need to pass the specific sheet to my showSheet method within FileController
and the showSheet method within SheetController needs to differentiate
between the 3 different ones in order to place the "withDescription"
NSString in the appropriate NSTextField of each sheet.
All buttons for each sheet are connected to various IBAction's in
FileController.
The resulting calls from FileController to SheetController look like this:
[theSheet showSheet:saveSheet forWindow:itsWindow
withDescription:nil onCompletion:nil]; *and*
**
please note that for now, I always pass nil for the completion selector
because I haven't *yet* figured out what to do within that selector
(probably just a long switch statement based on enumerated constants - I did
*not* know that Objective C is based on C, not C++ - I got "case identifier
needs constant integer", so placed constants inside an enum).
Anyway, I keep getting "unrecognized selector sent to instance ..." (see
footprint at the very bottom of this message).
In the meantime, I call within FileController:
shouldClose = ([theSheet getReturnCode] == doCloseDoc); // should I
close the mainWindow or not?
once I get a handle on that "unrecognized selector" error, I can get rid of
any calls from FileController to SheetController's getReturnCode.
**
an example of an IBAction method within FileController (that is connected
within IB to one of the sheet buttons):
- (IBAction) keeponCalculating:(id)sender {
[theSheet closeSheetWithCode:notCloseDoc]; // or, doCloseDoc, integers 0
or 1, depending on method
[self doSomethingHere];
}
The showSheet, getReturnCode and closeSheetWithCode methods within
SheetController looks like:
- (void) showSheet:(NSWindow*)whichSheet
forWindow:(NSWindow*)theWindow
withDescription:(NSString*)theDescription
onCompletion:(SEL)doThis {
if (theDescription) {
if (whichSheet == calculateSheet) {
if (calculateDescription) // if connected in IB
[calculateDescription setStringValue:theDescription];
}
else if (whichSheet == saveSheet) {
// etc
}
else if (whichSheet == errorSheet) {
// etc.
}
[NSApp beginSheet:whichSheet
modalForWindow:theWindow
modalDelegate:nil
// right now, I pass nil as doThis, but if I pass
@selector(sheetDidEnd:returnCode:contextInfo:)
// I get "unrecognized selector sent to instance ..."
didEndSelector:doThis
contextInfo:nil];
itsReturnCode = [NSApp runModalForWindow:whichSheet];
[NSApp endSheet:whichSheet];
[whichSheet orderOut:self];
}
/* -- doThis defined in FileController.m
- (void) sheetDidEnd:(NSWindow*)whichSheet
returnCode:(int)returnCode
contextInfo:(void*)contextInfo {
}
*/
- (int) getReturnCode {
return itsReturnCode;
}
- (void) closeSheetWithCode:(int)theCode {
[NSApp stopModalWithCode:theCode];
}
_______________________________________________
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