Re: NSSavePanel with a Sheet, strange callBack definition
Re: NSSavePanel with a Sheet, strange callBack definition
- Subject: Re: NSSavePanel with a Sheet, strange callBack definition
- From: Enrique Zamudio <email@hidden>
- Date: Mon, 11 Jun 2001 14:44:19 -0500
When it says that the didEndSelector has the following signature, it
means that the method you implement as the callback for the panel has to
be in that form (savePanelDidEnd:returnCo
de:contextInfo:). But it doesn't have to be called that way. These
callbacks are also valid:
- (void)sheetEnded:(NSWindow *)sheet rc:(int)returnCode
ci:(void *)contextInfo;
- (void)panelClosed:(NSWindow *)w retCode:(int)r context:(void *)ci;
The signature refers to the form of the method (it's split into three
parts to take three parameters, first a NSWindow, then an int, then a
memory address).
When you begin the sheet, there's a modal run loop that won't let the
user do anything outside of the open (or save) panel. But the beginSheet
method returns immediately. So when the user closes the panel (by
choosing a file, or canceling or whatever), the open/save panel calls
the method you told it to call, on the object you told it to send the
message to. Inside that callback method, you can get the filename(s)
chosen by the user with the proper methods. You can also know if the
user canceled by checking the returnCode parameter, so that you only
save or read a file if the user pressed the OK button.
NSOpenPanel and NSSavePanel are ultimately subclasses of NSWindow, but
that doesn't really concern you, since you rarely need to invoke window
methods on them. You just tell them to begin a sheet session, and then
get the results depending on the return code, and open the files the
user chose or save to the filename the user chose.