Re: NSView subclass does not seem to start
Re: NSView subclass does not seem to start
- Subject: Re: NSView subclass does not seem to start
- From: Alex Hall <email@hidden>
- Date: Mon, 30 Dec 2013 21:18:19 -0500
On Dec 30, 2013, at 6:05 PM, Ken Thomases <email@hidden> wrote:
> Hi,
>
> On Dec 30, 2013, at 4:34 PM, Alex Hall wrote:
>
>> Anyway, the problem remains that I need to capture keystrokes (and eventually mouse movements) in a subclass of NSView, but nothing seems to happen.
>
> In order for a view to receive key events, it must be the first responder. Typically, you need to override -acceptsFirstResponder to return YES to allow a view to become the first responder. (There are other approaches, but that's the normal one.)
I have done so. In AITAudioMenu (my subclass of NSView) I now have this method:
-(bool) acceptsFirstResponder{
return YES;
}
I assume, and the docs seem to indicate, that I never explicitly call this? It seems like something Cocoa does on its own, really a property setter more than anything.
>
> After that, you either want to set the window's initialFirstResponder to be that view before the window is shown or you want to call -[NSWindow makeFirstResponder:] to set the first responder at a later time.
I've done the latter, since the mainWindow will remain as I switch out views and set different ones to handle the keyboard and mouse at different times. ViewController now has a method that takes the view and window and sets the view as the first responder.
However, I still am getting no logs of keypresses. Is it possible that my use of mainWindow or some other variable or method name/signature is causing a conflict?
>
> Cheers,
> Ken
>
Have a great day,
Alex (msg sent from Mac Mini)
email@hidden
_______________________________________________
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