Re: NSTextField not consuming keyDown events; How do I prevent super view from receiving those events?
Re: NSTextField not consuming keyDown events; How do I prevent super view from receiving those events?
- Subject: Re: NSTextField not consuming keyDown events; How do I prevent super view from receiving those events?
- From: "email@hidden" <email@hidden>
- Date: Wed, 14 Mar 2012 09:47:46 +0000
On 14 Mar 2012, at 00:00, Eric Wing wrote:
> I am not calling [super keyDown:event] in my custom subclass. But the
> problem is that it is the NSTextField that is passing the event to my
> class, not the other way around. I did not subclass NSTextField (nor
> do I really want to).
>
Sorry Eric. I misconstrued your query.
> So I found a few solutions, but I'm hoping for something a little
> better, or perhaps assurance that this is a legitimate solution and I
> won't totally break things in some other way. (I'm wondering what the
> use case is for NSTextField not consuming the events.)
Events need to rise up the responder chain in order for key equivalents to reach the application menu.
Normally of course these use modifier keys but this doesn't have to be the case.
>
> - Put the text field inside another custom view that consumes the
> events before it reaches my real custom view.
>
> - Create a new responder that eats events and set the nextResponder of
> the NSTextField to this responder object.
>
> - Track the becomesFirstResponder and resignFirstResponder in my
> custom view and disregard all events that come it when it is NOT the
> firstResponder.
>
Stopping the events from rising up the responder chain may interfere with your application's menu.
You can just call -firstResponder in you NSView subclass to see if your view has first responder status in -keyDown:
> Simply doing the equivalent of setting a
> category on the super view for keyDown and inspecting the results.
Defining a category name with the same name as an existing method name leads to unpredictable behaviour.
That's why it is common practice to prefix public class category method names with a unique prefix.
Regards
Jonathan Mitchell
Mugginsoft LLP
_______________________________________________
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