Re: making NSView firstResponder/key
Re: making NSView firstResponder/key
- Subject: Re: making NSView firstResponder/key
- From: Roland King <email@hidden>
- Date: Sat, 17 May 2014 17:01:45 +0800
On 17 May, 2014, at 4:51 pm, Ken Thomases <email@hidden> wrote:
> On May 17, 2014, at 2:56 AM, Roland King wrote:
>
>> I have a custom NSView (actually subclass of NSTextField) in which I've overridden acceptsFirstResponder to return YES whether the superclass text field is editable or not. It also returns YES to canBecomeKeyView. I have 6 of them on-screen and lots of logging. The 6 are dynamically added, not from a nib.
>>
>> When the app starts the first one is asked if it can become first responder, says YES, asked it it can become key, says YES and indeed becomes first responder and hitting a key shows that view is getting keys it because it logs.
>>
>> If I mouse-click on another of the windows that window is asked if it can become first responder, it says YES, but nothing changes. The first one isn't asked to resign, the one I just clicked doesn't become first responder, it's not asked if it can become key, the key focus stays the same (another keypress is still handled by the same first custom view). I log the first responder each time and it never changes.
>>
>> The windows are chained to be each others nextResponder and nextKeyView. I can't find anything else to override. Surely the clicked NSView subclass should just become first responder (and key).
>
> Are you familiar with the concept of the field editor? You should search the docs and read up on it. A text field never becomes the first responder, as such. It uses a field editor and that's the first responder.
>
> Also, make sure your overrides are calling through to super.
>
> Regards,
> Ken
>
Looked at the field editor docs but it didn't instantly make sense. Which overrides were supposed to call through to super? Obviously not canBecomeFirstResponder etc as that's the behaviour I was trying to change. Do you mean becomeFirstResponder and resignFirstResponder? Those were just logging methods but indeed they didn't call through.
I went another way with this for this project and just quickly wrote my own NSView subclass which draws its own content, as the content here is trivially simple (it's one digit). That works perfectly and all the responder and key methods do exactly what I expected (all I did was change the base class to start with and they instantly began to work). So clearly I was breaking the NSTextField assumptions by overriding bits of it. I'll keep going the way I'm going with this one but I'd like to understand where I went wrong.
_______________________________________________
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