Re: Interface item validation through first responder
Re: Interface item validation through first responder
- Subject: Re: Interface item validation through first responder
- From: Quincey Morris <email@hidden>
- Date: Wed, 15 Jun 2011 10:25:09 -0700
On Jun 15, 2011, at 08:56, Luc Van Bogaert wrote:
> I'm not sure I understand how to accomplish this. What I have already tried, is message the window with "makeFirstResponder:" passing my view controllers as a parameter. This initially seemed to work fine; until I add an extra view with some textfields to the content pane. Now, it appears that my validation method does not get called anymore, leading me to the conclusion that somehow my view controllers are no longer part of the responder chain.
>
> I used NSLog to find out the kind of object that is my window's "first responder" and "next responder"; but the last method returns nil, which I don't understand.
I think there's still a small confusion here. For each window, there's a tree structure of NSResponder objects with the window at the root and the views as intermediate and leaf nodes. The nodes of this tree are linked (uni-directionally) by the "nextResponder" property.
A responder chain is something a bit more complicated. It's a traversal of a chain of objects beginning with a NSView, following the "nextResponder" links to the window, then continuing with a succession of objects (window controller, document, application, etc) that depends on which kind of responder chain (mouse, keyboard, action, etc) is being traversed.
Creating a view controller does *not* link it into the window's tree of responders, and therefore the view controller is not part of the responder chain. The "no longer" in your comment above doesn't apply: it was never in the chain.
In your scenario, where the view controller is playing little brother to the window controller -- is implementing and validating action methods -- it needs to be inserted manually into the tree of responders so that it *will* appear in the responder chain.
For example, you can do it in the 'loadView' override of a NSViewController subclass:
> - (void) loadView
> {
> [super loadView];
>
> // Insert this view controller into the responder chain
>
> NSResponder* nextResponder = self.view.nextResponder;
> self.view.nextResponder = self;
> self.nextResponder = nextResponder;
>
> }
_______________________________________________
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