[Q] Responder Chain & makeFirstResponder
[Q] Responder Chain & makeFirstResponder
- Subject: [Q] Responder Chain & makeFirstResponder
- From: Eric Gorr <email@hidden>
- Date: Wed, 4 Mar 2009 10:35:00 -0500
The documentation for NSWindow's makeFirstResponder states:
If responder does not accept first responder status,
the NSWindow object becomes first responder; in this
case, the method returns YES even if responder
refuses first responder status.
In my case, the behavior I would like to see if if responder does not
accept first responder status, that the superview is made the first
responder and if that fail's then it's superview is tried, etc.
It appears I can make this happen if I alter the the
becomeFirstResponder method for the views whose superviews should
actually be made the first responder to be the following:
- (BOOL)becomeFirstResponder
{
return [[self window] makeFirstResponder:[self superview]];
}
However, this does not seem like it is the right way to do this. Or,
is it?
The right thing to do may be to just store a variable with what I know
should be made the first responder and just call makeFirstResponder on
it, but I wasn't sure if this would be considered the right way either.
If you need more details on what I am doing, overall, what I am doing
looks like:
http://ericgorr.net/cocoadev/outlinetable/outlineview.png
This is a custom implementation of a table of items. (If you need to
know why, it is because none of the Apple supplied controls have all
the features I need.)
The items in the table are:
http://ericgorr.net/cocoadev/outlinetable/namedparts.png
(although, the NSTextField is now just my own custom NSView
(MyItemLabel) which draws text using a NSLayoutManager.)
Neither an item or the label of the image should ever be the first
responder. What should become the first responder is my custom table.
When the user double-clicks on a label, I insert an editable
NSTextView and make it the first responder. When the user presses
return, MyItemLabel gets a textDidEndEditing: notification which
removed the NSTextView being used to edit the text.
The question becomes how to get the first responder back to the table
view where it belongs.
Before I had fully read the documentation on makeFirstResponder, I
expected:
[[self window] makeFirstResponder:self];
which I placed in the textDidEndEditing: method, to automatically
propagate first responder status up through the superviews. But, since
MyItemLabel rejects first responder status, the window was being made
the first responder.
_______________________________________________
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