Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTextField Selection Problem



Tom,

Instead of selecting using the NSTextField, try it's field editor. Since the NSTextField is active, the field editor should be valid and attached to it.

Rather than:
[myNSTextField selectText:nil]

try:
if ([myNSTextField currentEditor] != nil)
{
[[myNSTextField currentEditor] setSelectedRange:NSMakeRange(0, [[[myNSTextField currentEditor] string] length])];
}

// I actually used "control" rather than "myNSTextField" since it was in the control:textShouldEndEditing: method, but that'll depend on how you have things set up.


You shouldn't have to wrap the setSelectedRange: call in the if statement, but that will make sure that nothing goes awry in setting up the range. I just put that into a test project of mine and I didn't get an infinite loop (except that I could never get out of editing since I was always returning NO from control:textShouldEndEditing:, but I presume you aren't doing that).

Hope this helps -- I've been waist-deep in NSTextField/fieldEditor stuff lately, so it is fresh in my mind.

chris


On Saturday, December 7, 2002, at 09:14 AM, Tom Gray wrote:

As always, thanks for the help guys!

Here is my problem.

I have a series of NSTextFields into which a user of my application is entering some preference information. I validate the information entered with control:textShouldEndEditing:

What I want to do is to select the current NSTextField value in the control:textShouldEndEditing: method. I have tried to do that with [myNSTextField selectText:nil] but I seem to be in a recursive loop!

From what I can ascertain, adding the [myNSTextField selectText:nil] line to my control:textShouldEndEditing: method creates an infinite loop!

It appears like the [myNSTextField selectText:nil] method causes the control:textShouldEndEditing: method to be called.

So, the goal is to validate the text in an NSTextField and to select the text if it is not valid.

(In my simple case I am simply checking the length of a user entered password.)

Tom Gray
-------------
email@hidden
or
email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >NSTextField Selection Problem (From: Tom Gray <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.