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: Tue, 14 Jun 2011 13:39:17 -0700
On Jun 14, 2011, at 13:20, Luc Van Bogaert wrote:
> The contentview of my main window is designed to contain one of two different views, to be selected by the user at runtime. So the view controllers are not instantiated in IB, but rather in code during runtime.
>
> All the menu items and buttons in the interface use the target-action mechanism, but because of the previous design decision, I am targetting the "first responder" object instead of the actual view controller objects. When the user switches views held by the main window, I'm making sure the selected view also becomes first responder. So far so good.
>
> But now a problem comes up when adding another view to the interface. As this extra view contains some textfields, selecting one of the text fields makes it first responder, which in turn breaks my interface item validation, because now the targetted actions can no longer be found as part of the active first responder object.
>
> So, I seem to be forced to implement all my action methods in the AppDelegate instead of in my view controllers, or is there some better way to solve this problem?
You're mixing up a couple of different things here.
When you connect an action to "First Responder", that doesn't mean that it's sent to the first responder object, but rather that it's sent to the first object in the responder chain that implements the action. Therefore, in situations like this, you need to insert your view controller into the responder chain. Set the view's next responder to be the view controller, and set the view controller's next responder to be whatever the view's next responder used to be.
The validation message gets sent to whatever object has been chosen to perform the action (that is, if the action is directed at "First Responder", the target is determined first, and validation is sent to that object). The responder chain isn't involved directly in validation, because the target is already known.
For actions implemented in your view controller, your validation method can choose to "delegate" validation to other implementations (e.g. super) or to other objects (e.g. a window controller). Normally, though, the fact that the validation message has arrived at the view controller means that the view controller is the object that knows how to do the validation, so the flexibility that's theoretically available here is of limited use.
_______________________________________________
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