Re: Why is viewDidMoveToWindow called multiple times?
Re: Why is viewDidMoveToWindow called multiple times?
- Subject: Re: Why is viewDidMoveToWindow called multiple times?
- From: Ricky Sharp <email@hidden>
- Date: Mon, 6 Dec 2004 17:06:32 -0600
On Dec 6, 2004, at 4:55 PM, Ricky Sharp wrote:
It's still the case where viewDidMoveToWindow is being called twice.
I believe this is because when I load in a particular nib, the nib
contains an NSPanel which in turn holds all my custom views. At app
startup time, I take the contentView of that NSPanel and set it as the
contentView of my main window.
So it does make sense that the API is being called twice since my
views ultimately reside in two different windows during their
lifetime.
Apparently though, I don't have the proper code in place to remove the
tracking rects when the views hop from one window to another. It
appears the code is doing this:
- nib loaded, NSPanel instantiated, custom views awoken
- for each custom view, viewDidMoveToWindow is called, tracking rect
is set up against the NSPanel
- contentView of main window is set with NSPanel's contentView
- for each custom view, viewDidMoveToWindow is called.
But, the instances of my views still have their trackingRectTag iVar
set (with the original value when adding to the NSPanel). So when
viewDidMoveToWindow is called a second time on my view intsances,
resetTrackingRect attempts to remove that already established tracking
rect, but blows up because the view now belongs to a different window.
As I suspected, the answer was in the docs. I now provide an
implementation for viewWillMoveToWindow to ensure that my tracking rect
is removed from the current window before it hops onto a new one:
- (void)viewWillMoveToWindow:(NSWindow*)newWindow
{
if (trackingRectTag)
{
[self removeTrackingRect:trackingRectTag];
}
trackingRectTag = 0;
[super viewWillMoveToWindow:newWindow];
}
___________________________________________________________
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