Re: How select NSTextField programatically?
Re: How select NSTextField programatically?
- Subject: Re: How select NSTextField programatically?
- From: Peter <email@hidden>
- Date: Tue, 13 Dec 2011 17:53:05 +0100
Am 13.12.2011 um 17:15 schrieb Kyle Sluder:
> On Tue, Dec 13, 2011 at 8:10 AM, McLaughlin, Michael P. <email@hidden> wrote:
>> I have a Cocoa "dialog" with several textfields for numerical input. When the user enters a bad value, I want to select that view programatically along with an NSBeep() so that the user can fix it.
>>
>> What is the best way to select that subview given that I know its tag?
>
> Why tags? Use an outlet. Then just call -selectText:.
>
> --Kyle Sluder
Or if you like it a bit more twisted (I guess that in your case outlets might not be an option if you have many text fields wired up to the controller via bindings), although I am not sure what you mean by "select that subview" - I take it to mean "select the bad input value in the current field editor":
In the respective delegate method (control:textShouldEndEditing: most likely), use the field editor from the method (or get it from the userInfo in the notification (key @"NSFieldEditor") for the other methods), and talk to it, i.e. -selectAll or the like.
Most likely you need to check which text field makes currently use of field editor in order to make a proper decision: go ahead and ask the field editor in turn for its delegate: While the field editor is active in a text field, this text field is set as its delegate. Ask the delegate for its tag or send whatever message the delegate knows about.
_______________________________________________
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