Re: Correct way to create a subview at runtime [Solved]
Re: Correct way to create a subview at runtime [Solved]
- Subject: Re: Correct way to create a subview at runtime [Solved]
- From: Ken Tozier <email@hidden>
- Date: Sun, 22 Apr 2007 05:05:36 -0400
Never mind. I finally tracked the problem down to an orphaned
tracking rectangle. Once I made sure that all tracking rects were
disposed of correctly, everything started to work as expected.
On Apr 21, 2007, at 11:04 PM, Ken Tozier wrote:
I guess this question can be simplified to this: How is it
possible for the NSView method "removeFromSuperview" to not
propagate the subview deletion to the window manager? There is
exactly one instance of my matrix class alive at any one time and I
don't connect to it either through observers, retains etc so I
don't understand why the window server is sending "mouseEntered"
events to released objects.
Can anyone think of a reason for this?
Thanks for any help
Ken
On Apr 21, 2007, at 7:57 PM, Ken Tozier wrote:
Hi
My custom view class completely flushes it contents in response to
runtime context changes in a host app. I thought this would be
extremely straight forward and simple, but apparently I'm messing
up somewhere. What's happening is that if I alloc/init a new
subview its dealloc method never gets called. If I instead create
it with alloc/init/autorelease, it's dealloc method does get
called but it creshes the app and NSZombie returns the following
error:
*** Selector 'mouseEntered:' sent to dealloced instance 0x1ef4cfc0
of class KWrappingMatrix.
My "createPageModeView" method is the only location in the plugin
where I create KWrappingMatrix instances and the only thing that
references them is an NSTimer which is turned off in the
removeFromSuperview loop with a call to the KWrappingMatrix
invalidateMouseSampler method.
Nothing in my code manually invokes the KWrappingMatrix
"mouseEntered" method, so the only place it could be coming from
is the window manager. Why is it sending messages to a disposed
object?
Thanks for any help
Ken
Here's the code
- (void) createPageModeView
{
if (publicationView != nil)
{
NSEnumerator *enumerator = [[publicationView subviews]
objectEnumerator];
id sub;
SEL sel = @selector(invalidateMouseSampler);
while (sub = [enumerator nextObject])
{
if ([sub respondsToSelector: sel])
[sub performSelector: sel];
[sub removeFromSuperview];
}
// if allocated with the next line, the matrix dealloc method
never gets called
//KWrappingMatrix *matrix = [[KWrappingMatrix alloc]
initWithFrame: [publicationView frame]];
// if allocated with the next line, the matrix dealloc method
does get called but NSZombie
// returns the error:
// *** Selector 'mouseEntered:' sent to dealloced instance
0x1ef4cfc0 of class KWrappingMatrix.
KWrappingMatrix *matrix = [[[KWrappingMatrix alloc]
initWithFrame: [publicationView frame]] autorelease];
[publicationView addSubview: matrix];
}
}
The "mouseEntered" method is defined like this and is where a
timer is created.
- (void) mouseEntered:(NSEvent *) inEvent
{
NSLog(@"adding mouse sampler");
[self activate];
// add mouse sampler
mouseSampler = [NSTimer scheduledTimerWithTimeInterval: .02
target: self
selector: @selector(sampleMouse:)
userInfo: nil
repeats: YES];
}
The mouse out is defined like this and is where the timer is
invalidated
- (void) mouseExited:(NSEvent *) inEvent
{
NSLog(@"removing mouse sampler");
[self deactivate];
if (mouseSampler != nil)
{
[mouseSampler invalidate];
mouseSampler = nil;
}
}
Invalidate mouse sampler is defined like this: (called from
removeFromSuperview of createPageModeView)
- (void) invalidateMouseSampler
{
if (mouseSampler != nil)
{
[mouseSampler invalidate];
mouseSampler = nil;
}
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
40comcast.net
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
40comcast.net
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden