Re: NewbieQ: Why can't I have a customview as an initalResponder??
Re: NewbieQ: Why can't I have a customview as an initalResponder??
- Subject: Re: NewbieQ: Why can't I have a customview as an initalResponder??
- From: otto <email@hidden>
- Date: Mon, 21 Jan 2002 20:57:36 -0800
On Monday, January 21, 2002, at 01:30 PM, Andrew Platzer wrote:
On Saturday, January 19, 2002, at 08:13 , email@hidden wrote:
Newbie here. I want to have a custom view be the initial responder
in a simple window, but I can't make it work. As a test, I created a
window in IB with just a custom view, and then set the Window's
initialFirstResponder outlet to the CustomView (after setting the
customview's class to my custom view). But the @#$@#% custom view does
not come up as the first responder.
If I throw a textfield onto the window, IT becomes the
initalResponder, even though IB says that my custom view is the first
responder.
My custom view does nothing but paint it self red when its NOT the
responder, and green when it is. When the window opens the view comes
up red, until I click on it, and then it turns green.
I have NSLog messages that show that the CustomView receives an
acceptsFirstResponder message (which it answers YES), but it never
gets a becomeFirstResponder message until I click on it.
The test code is tiny and is attached to the bottom of this message.
Is there some law against custom views being the first responder or am
I just missing some magic cocoa beans??
By default, unless you have full keyboard UI turned on, only controls
like NSTextField and NSBrowser can accept first responder status.
That's why it jumps to a text field on loading the nib. If your control
is similar in that it always wants to accept key focus, override the
method -[NSView needsPanelToBecomeKey] to return YES.
This method is poorly named (historical reasons) and we are looking at
making it a bit more obvious what to override to get the behaviour you
want and adding to the documentation.
I have the same problem. I'm using a subclass of NSImageView that's
connected to my document window's initialFirstResponder outlet in IB.
but even after overriding needsPanelToBecomeKey: to return YES, it won't
become first responder after the nib is loaded.
needsPanelToBecomeKey: doesn't even seem to get called until I click the
custom view.
Of course I could make my view first responder by calling my window's
makeFirstResponder: method, but I'd rather understand what's going on
here..
TIA,
-otto.