Skip navigation.
 
mlRe: Selecting an NSTextField
FROM : Christiaan Hofman
DATE : Tue Mar 04 11:02:27 2008

On 4 Mar 2008, at 5:21 AM, Chad Armstrong wrote:

> Hello:
>
> I'm looking for a way to programmatically select an NSTextField so 
> it is ready to be edited.  I've found a way to do this with an 
> NSTextView, as such:
>
> [theWindow makeFirstResponder: theTextView];
> [theTextView setSelectedRange:NSMakeRange(0,0)];
>
>
> However, I'm not having luck finding a way to do a similar thing 
> with an NSTextField.  I can "highlight" the text field with a line 
> of code like this:
>
> [[self window] makeFirstResponder: myTextField];
>
> But this does not put the cursor in the field so I can start typing 
> immediately.  What am I missing?  It seems that this should be 
> fairly easy to do, but I'm just not finding the answer.
>
> - Chad


You can use -selectText:. Read the documentation about the field 
editor <http://developer.apple.com/documentation/Cocoa/Conceptual/TextArchitecture/Concepts/TextFieldsAndViews.html
> what you're missing.

Christiaan

Related mailsAuthorDate
mlSelecting an NSTextField Chad Armstrong Mar 4, 05:21
mlRe: Selecting an NSTextField Christiaan Hofman Mar 4, 11:02
mlRe: Selecting an NSTextField Chad Armstrong Mar 5, 02:51