I'm trying to emulate the tokenized search feature of Mail.app and Finder.app on 10.7+ where there is what looks to be an NSSearchField with a search magnifying glass icon on the left and cancel (x) button on the right, but also includes tokens inside the search field.
Is there any way to make NSSearchField use an NSTokenFieldCell instead of an NSSearchFieldCell? I've tried calling -setCell:
on the NSSearchField instance, which works and appears to swap out the cell as evidenced by calling po [searchField cell]
in the debugger, but the drawing of the search field breaks and no text field is drawn.
Am I approaching this in the right way or is there a better way to do it? Thanks!
Update 10/25/2016: Using the Accessibility Inspector I found that Finder and Mail use a mix private subclasses:
SGTSearchField : NSSearchField
SGTSearchFieldCell : NSSearchFieldCell
SGTTokenFieldCell : NSTokenFieldCell
These are part of a private framework called Suggestions.framework
. Hopefully Apple will make these classes public in the future. Make sure to file a radar if you'd like to see this functionality public too.
Best answer I have for you two is to simply go with an NSTokenField. You might be able to modify it to display the little search icon. But if that's not make or break, you can get a lot of tokenized functionality from NSTokenField.