Re: Programmatically created NSView subclasses, and mouse events
Re: Programmatically created NSView subclasses, and mouse events
- Subject: Re: Programmatically created NSView subclasses, and mouse events
- From: Graham Cox <email@hidden>
- Date: Fri, 18 Feb 2011 17:43:50 +1100
On 17/02/2011, at 4:36 AM, Howard Moon wrote:
> I'm teaching myself Objective-C and Cocoa, by working on a simple (so I thought) modification to the default AudioUnit effect project. But in this project, I create my own views programmatically instead of using the NIB. (I know - why??? Just go with me, ok? :-))
>
> I have a hierarchy of NSView descendants, and ones below a certain "base" class in the hierarchy need to respond to mouse clicks. (Other branches do not.)
>
> My first attempt was to add -mouseUp: and -mouseDown: to the "base" class that directly inherits from NSView, and then only override those in subclasses that need changes to the default behavior. However, none of my subclasses of that "base" class respond to mouse clicks when I do it that way.
If I've understood this correctly, what you suppose should happen, should happen.
If you have NSView -> Subclass A -> Subclass B and subclass A overrides mouseDown: and mouseUp:, then subclass B should get that implementation.
> Shouldn't all derived classes inherit the behavior of their ancestors, including those functions?
Yep, they should.
> I'm *guessing* that is has something to do with the way events are handled, and that some kind of check is done to make sure the class implementing those functions is in fact the same class as the target of the event, but that's just a guess. My alternate guess is that's the way Objective-C works.
No. You must have made a mistake.
Are you sure you're overriding the right method? it must match the original method's signature exactly. Are you sure you are inheriting the right class, i.e. subclass B inherits subclass A, not NSView?
Show your actual code.
--Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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