Why is viewDidMoveToWindow called multiple times?
Why is viewDidMoveToWindow called multiple times?
- Subject: Why is viewDidMoveToWindow called multiple times?
- From: Ricky Sharp <email@hidden>
- Date: Mon, 6 Dec 2004 16:25:04 -0600
I've recently added mouseOver effects to one of my custom NSControl
objects. I followed the advice outlined at:
<>
to call addTracking:owner:userData:assumeInside: from
viewDidMoveToWindow as follows:
- (void)viewDidMoveToWindow
{
[self resetTrackingRect];
}
- (void)resetTrackingRect
{
if (trackingRectTag)
[self removeTrackingRect:trackingRectTag];
NSRect theTrackingRect = [self frame];
theTrackingRect.origin = NSZeroPoint;
trackingRectTag = [self addTrackingRect:theTrackingRect
owner:self userData:nil assumeInside:NO];
}
But my app would hang or crash. I added some logging, turned on
zombies, etc. and found that viewDidMoveToWindow was being called a
second time for each of my custom NSControl objects. When called for a
second time, I'd get this in my log output when resetTrackingRect calls
removeTrackingRect:
2004-12-06 16:20:45.488 Shell[1412] *** Assertion failure in
-[IIContentWindow _discardTrackingRect:],
AppKit.subproj/NSWindow.m:2796
2004-12-06 16:20:45.489 Shell[1412] Exception raised during posting of
notification. Ignored. exception: Window: discardTrackingRect called
before adding rect
I then removed the [self resetTrackingRect] from viewDidMoveToWindow to
see just how many times it was being called. For each of my custom
objects, viewDidMoveToWindow is being called six times.
So, question #1 is why is that API being called 6 times? I would have
thought it would be called just once.
Question #2 is why would resetTrackingRect blow up when being called a
2nd, 3rd, etc. time? I have a feeling that my app is in a hosed state
and the fact that viewDidMoveToWindow is being called over and over
again is the real problem here.
___________________________________________________________
Ricky A. Sharp mailto:email@hidden
Instant Interactive(tm) http://www.instantinteractive.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden