• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Correct way to create a subview at runtime
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Correct way to create a subview at runtime


  • Subject: Re: Correct way to create a subview at runtime
  • From: Ken Tozier <email@hidden>
  • Date: Sat, 21 Apr 2007 23:04:17 -0400

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Correct way to create a subview at runtime [Solved]
      • From: Ken Tozier <email@hidden>
References: 
 >Correct way to create a subview at runtime (From: Ken Tozier <email@hidden>)

  • Prev by Date: Re: Undo Manager (hac)
  • Next by Date: Re: Cocoa-dev Digest, Vol 4, Issue 390
  • Previous by thread: Correct way to create a subview at runtime
  • Next by thread: Re: Correct way to create a subview at runtime [Solved]
  • Index(es):
    • Date
    • Thread