Search code examples
objective-cmacoscocoanssearchfield

NSSearchField: how to clear selection (set selected range)


I can select all text in a NSSearchField by invoking its selectText: message (which is probably meant for the "Select All" menu item).

But how do I clear the selection, e.g. set the text cursor to the edit field's end, after I've set the text field with setStringValue:? (Note: setStringValue: selects the text automagically, which I don't want.)

I've tried invoking setSelectedRange: but that message is not understood by NSSearchField instances, it appears.


Solution

  • Try this one:

    [[self.searchField currentEditor] moveToEndOfLine:nil];