Re: Trouble with a save panel
Re: Trouble with a save panel
- Subject: Re: Trouble with a save panel
- From: David Wood <email@hidden>
- Date: Sun, 16 Mar 2003 08:38:59 -0500
On Sunday, March 16, 2003, at 08:16 AM, Sherm Pendley wrote:
On Saturday, March 15, 2003, at 07:09 PM, David Wood wrote:
..and it shows on the screen like a regular dialog box, separate from
the program's main window.
It sounds like a silly question, but is "self" what you think it is?
Could it be getting autoreleased, perhaps, and the memory re-used for
another object?
Ahhhh, I anticipated your question, it seems. I wrote some NSLog
statements into it to check it out:
- (IBAction)savePDF:(id)sender
{
NSSavePanel *panel = [NSSavePanel savePanel];
[panel setRequiredFileType:@"pdf"];
NSLog(@"As of this writing... [self window] = %@",[self window]);
NSLog(@"And self = %@",self);
[panel beginSheetForDirectory:nil
file:nil
modalForWindow:[self window]
modalDelegate:self
didEndSelector:@selector(didEnd:returnCode:contextInfo:)
contextInfo:nil];
}
The docs for NSSavePanel indicate that, if the modalForWindow:
parameter is nil, the resulting panel is displayed as a dialog, not a
sheet. Also, if nil is passed to the modalDelegate: parameter, or if
the object passed as the delegate doesn't have the named
didEndSelector:, that would cause the resulting didEnd: selector to
never get called.
The above code, run just a few minutes ago, returns this:
2003-03-16 08:21:03.010 TypingTutor[3021] As of this writing... [self
window] = (null)
2003-03-16 08:21:03.010 TypingTutor[3021] And self = <BigLetterView:
0x1842d0>
It does indeed return null for [self window], which explains the sheet
vs. dialog problem. But it correctly identifies its class in the
following line, and the function in didEnd:returnCode:contextInfo:
class does indeed exist in it. It's defined like:
- (void)didEnd:(NSSavePanel *)sheet
returnCode:(int)code
contextInfo:(void *)contextInfo
{
NSRect r;
NSData *data;
if (code == NSOKButton) {
r = [self bounds];
data = [self dataWithPDFInsideRect:r];
[data writeToFile: [sheet filename] atomically:YES];
}
}
I bookmarked it in the debugger; no amount of clicking on the browser
(which looks broken, by the way -- missing icons and item names) or the
buttons successfully ends the modal sheet. The code never gets called
up, I think because the dialog can't handle any events correctly. But
I'm not sure how to test that.
The program won't do a normal quit under those circumstances. I end up
having to scooch it by selecting Quit from the Dock menu, or killing it
from Project Builder.
sherm--
If you listen to a UNIX shell, can you hear the C?
--David
http://skipjack.bluecrab.org/~dwood
"Only a really good technician can completely insulate management from
the ugly inner workings of a complicated system.
And only a bad manager would willingly accept that insulation."
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.