Re: Getting hitTest of Subview
Re: Getting hitTest of Subview
- Subject: Re: Getting hitTest of Subview
- From: j o a r <email@hidden>
- Date: Sat, 2 Nov 2002 13:42:10 +0100
On Saturday, Nov 2, 2002, at 12:23 Europe/Stockholm, Craig Bakalian
wrote:
-(void)mouseUp: (NSEvent *) event
{
NSPoint loc = [event locationInWindow];
NSPoint vLoc = [self convertPoint: loc fromView: nil];
NSRect myRect = NSMakeRect(vLoc.x, vLoc.y, 100.0, 24.0);
CBNote *myNote = [[CBNote alloc] initWithFrame: myRect];
[self addSubview: myNote];
}
Don't forget to release the new subview, or else you will most likely
leak! Something like this:
- (void) mouseUp: (NSEvent *) event
{
NSPoint loc = [self convertPoint: [event locationInWindow]
fromView: nil];
CBNote *myNote = [[CBNote alloc] initWithFrame: NSMakeRect(loc.x,
loc.y, 100.0, 24.0)];
[self addSubview: myNote];
[myNote release]; // The note is now only retained by it's
superview
}
The CBNote is a subclass of NSView. It just draws a @"Hello World".
This works fine. OK, how do I get a hitTest for this added subview? I
feel lost in responders, locations, and superviews.
How do you mean "get a hitTest"? As soon as it is inserted in the
superview it should get mouse click events automatically. If your
CBNote class implements "mouseDown:" it should get called when you
click it - is this not working?
j o a r
_______________________________________________
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.