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 09:23:47 -0500
To those who have offered help, the strangeness continues:
For some reason, the initializer on this custom view:
- (id)initWithFrame:(NSRect)Rect
{
if (self = [super initWithFrame:Rect]) {
NSLog(@"Initializing view");
[self prepareAttributes];
[self setBgColor:[NSColor yellowColor]];
[self setString:@" "];
}
return self;
}
...gets called TWICE. So I got curious, adjusted the NSLog statement
within it, and boggled at the result:
2003-03-16 09:07:18.786 TypingTutor[3128] Initializing view. My window
is (null)
2003-03-16 09:07:18.813 TypingTutor[3128] The string is now " "
2003-03-16 09:07:18.828 TypingTutor[3128] Initializing view. My window
is (null)
2003-03-16 09:07:18.845 TypingTutor[3128] The string is now " "
Not only does the initializer get called twice, but BOTH times it
denies it's in a valid window, which draws successfully on the screen.
I realized I had a [self window] call elsewhere in the code, and put a
debug statement there TOO:
- (void)keyDown: (NSEvent *)event {
NSString *input = [event characters];
NSLog(@"Just checking: [self window] = %@",[self window]);
// Is it a tab?
if ([input isEqual:@"\t"]) {
[[self window] selectNextKeyView:nil];
return;
}
// Is it a shift-tab?
if ([input isEqual:@"\031"]) {
[[self window] selectPreviousKeyView:nil];
return;
}
// Set string to what the user typed
[self setString:input];
}
...and this is the full log of the session in question, anotated:
2003-03-16 09:12:29.952 TypingTutor[3158] Initializing view. My window
is (null)
2003-03-16 09:12:29.954 TypingTutor[3158] The string is now " "
2003-03-16 09:12:29.955 TypingTutor[3158] Initializing view. My window
is (null)
2003-03-16 09:12:29.955 TypingTutor[3158] The string is now " "
The initializer called twice, both times with (it thinks) no window.
"Smart objects" my eye!
acceptsFirstResponder, becomeFirstResponder, and resignFirstResponder
all got log statements to show event handling, so log statements got
stuck into them as part of the exercise, to show the handlers in
action. That's why there's this:
2003-03-16 09:12:32.551 TypingTutor[3158] Accepting
2003-03-16 09:12:32.551 TypingTutor[3158] Accepting
2003-03-16 09:12:32.551 TypingTutor[3158] Accepting
2003-03-16 09:12:32.551 TypingTutor[3158] Accepting
(Did you know acceptsFirstResponder gets culled multiple times before
the thing actually gets tapped to be First Responder? Seems
inefficient, doesn't it?)
2003-03-16 09:12:32.551 TypingTutor[3158] Becoming
2003-03-16 09:12:33.184 TypingTutor[3158] Just checking: [self window]
= <NSWindow: 0x18a110>
This is where the object actually receives its own keyDown event. When
queried HERE, it CAN find its window.
In other words, BUH??
2003-03-16 09:12:33.185 TypingTutor[3158] Resigning
2003-03-16 09:12:33.801 TypingTutor[3158] Accepting
2003-03-16 09:12:33.801 TypingTutor[3158] Accepting
2003-03-16 09:12:33.801 TypingTutor[3158] Accepting
2003-03-16 09:12:33.801 TypingTutor[3158] Accepting
2003-03-16 09:12:33.801 TypingTutor[3158] Becoming
2003-03-16 09:12:34.324 TypingTutor[3158] Just checking: [self window]
= <NSWindow: 0x18a110>
2003-03-16 09:12:34.324 TypingTutor[3158] Resigning
2003-03-16 09:12:34.940 TypingTutor[3158] Accepting
2003-03-16 09:12:34.940 TypingTutor[3158] Accepting
2003-03-16 09:12:34.940 TypingTutor[3158] Accepting
2003-03-16 09:12:34.940 TypingTutor[3158] Accepting
2003-03-16 09:12:34.940 TypingTutor[3158] Becoming
2003-03-16 09:12:36.513 TypingTutor[3158] Just checking: [self window]
= <NSWindow: 0x18a110>
A few more times to verify that it can find its window with both hands
and a packet sniffer...
2003-03-16 09:12:36.513 TypingTutor[3158] The string is now "P"
...the posting of data so it has something to write out to the PDF, and
then, KER-WHAM:
2003-03-16 09:12:42.608 TypingTutor[3158] As of this writing... [self
window] = (null)
2003-03-16 09:12:42.609 TypingTutor[3158] And self = <BigLetterView:
0x196f10>
The savePDF call itself. It knows what it is, but it can't find its
window. The sheet comes up as a dialog window, and hitting anything
other than the cancel button, which does nothing, gets stuff like this:
2003-03-16 09:12:47.596 TypingTutor[3158] *** -[NSCFArray
objectAtIndex:]: index (3) beyond bounds (0)
2003-03-16 09:12:48.336 TypingTutor[3158] *** -[NSCFArray
objectAtIndex:]: index (3) beyond bounds (0)
2003-03-16 09:12:51.305 TypingTutor[3158] Exception raised during
posting of notification. Ignored. exception: *** -[NSCFArray
objectAtIndex:]: index (4) beyond bounds (0)
2003-03-16 09:12:51.443 TypingTutor[3158] Exception raised during
posting of notification. Ignored. exception: *** -[NSCFArray
objectAtIndex:]: index (4) beyond bounds (0)
2003-03-16 09:12:51.612 TypingTutor[3158] Exception raised during
posting of notification. Ignored. exception: *** -[NSCFArray
objectAtIndex:]: index (4) beyond bounds (0)
2003-03-16 09:12:51.805 TypingTutor[3158] Exception raised during
posting of notification. Ignored. exception: *** -[NSCFArray
objectAtIndex:]: index (4) beyond bounds (0)
2003-03-16 09:12:52.039 TypingTutor[3158] Exception raised during
posting of notification. Ignored. exception: *** -[NSCFArray
objectAtIndex:]: index (4) beyond bounds (0)
2003-03-16 09:12:52.061 TypingTutor[3158] Exception raised during
posting of notification. Ignored. exception: *** -[NSCFArray
objectAtIndex:]: index (4) beyond bounds (0)
2003-03-16 09:12:52.113 TypingTutor[3158] Exception raised during
posting of notification. Ignored. exception: *** -[NSCFArray
objectAtIndex:]: index (4) beyond bounds (0)
2003-03-16 09:12:52.554 TypingTutor[3158] Exception raised during
posting of notification. Ignored. exception: *** -[NSCFArray
objectAtIndex:]: index (4) beyond bounds (0)
2003-03-16 09:12:52.712 TypingTutor[3158] Exception raised during
posting of notification. Ignored. exception: *** -[NSCFArray
objectAtIndex:]: index (4) beyond bounds (0)
2003-03-16 09:12:52.882 TypingTutor[3158] Exception raised during
posting of notification. Ignored. exception: *** -[NSCFArray
objectAtIndex:]: index (4) beyond bounds (0)
2003-03-16 09:12:53.052 TypingTutor[3158] Exception raised during
posting of notification. Ignored. exception: *** -[NSCFArray
objectAtIndex:]: index (4) beyond bounds (0)
2003-03-16 09:12:53.103 TypingTutor[3158] Exception raised during
posting of notification. Ignored. exception: *** -[NSCFArray
objectAtIndex:]: index (4) beyond bounds (0)
2003-03-16 09:12:53.163 TypingTutor[3158] Exception raised during
posting of notification. Ignored. exception: *** -[NSCFArray
objectAtIndex:]: index (4) beyond bounds (0)
TypingTutor has exited with status 0.
Here I had to use Quit from the Dock menu.
There has to be a logical explanation for this, right? I mean, years
later we'll look back at the very basic mistake I made somewhere in
here, and my therapist and I will *laugh*...
--David
http://skipjack.bluecrab.org/~dwood
"Never mind working on your own computer, or the PlayStation in the
other room. The biggest advantage to working at home is the ability to
apply hydrocortisone cream WHERE you want WHEN you want."
_______________________________________________
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.