Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Howiieque

macrumors regular
Original poster
Feb 1, 2009
120
0
hello, everybody.
i have a nswindow and it contains myview. the myview has a myviewcontroller.

1.
within the myviewcontroller.m,
...
[[myview window] makeFirstResponder: myview];
…

then whether the myview' s acceptsFirstResponder: method returns YES or NO, myview will become the first responder.

according to apple's documentation, it should not be the first responder, when acceptsFirstResponder: method returns NO.

2.
if i set override the acceptsFirstResponder: and make it return YES. the myview becomes the first responder automatically. i even don't need to send makeFirstResponder: or set it in the IB.

why would it have have the chance to became the first responder?

could someone explain these? it's very confusion.
 
Because the first responder may need to change its state from inactive to active. A Text Box for example will have the cursor blinking, a focus ring around it and any text typed will end up inside it.
 
but the view explicitly says it refuse to become the first responder. but why does it end up being the first responder?
 
Two things happen to make a view the first responder. The method above lets the view's controller know that the view can become first responder. But then the view must return "YES" to the method -becomeFirstResponder. This method is defined in NSResponder, which is a superclass of NSView and all its various subclasses, and by default, it returns "YES", where as NSResponder's default value for -acceptsFirstResponder is "NO". If you return "YES" to -acceptsFirstResponder, your view will automatically become first responder and keep that status as long as no other view takes it.

First responder status is really only important in two ways. It allows a view to subclass the methods that handle the keyboard, and it relates to nil-targeted actions (such as an menu action that sends to first responder). If neither of these things are used in your myview class, first responder status does not really matter.
 
thank you very much.

but even the view returns NO, the controller can still make it the first responder. could you explain a bit about the reason.

and if there is more than one view(or its subview, button, switch, etc) returns NO, which will become the first responder. say a view contain text fields and button.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.