Adding a Search Field to Your Application
You can create a search field programatically, but the easiest way to add a search field to your application is to create it in a xib file in Xcode. Simply drag a search field from the Controls library and add it to a window.
In Xcode, you can use the Attributes Inspector to set search-field-specific attributes:
Autosave Name, which if set, the recent search list is saved to an application preference using the name provided, and restored the next time the recents list is needed for the popup menu. You can also programmatically send the
setRecentsAutosaveName:
message. Setting the autosave name tonil
does not clear out any saved lists. Setting the autosave name to a valid string discards any current recents and loads the recents from the user defaults.Recents, which specifies the maximum number of recent searches to show in the recents menu. You can also programmatically send the
setMaximumRecents:
message to the search field’s cell.Behavior, which specifies whether the search field sends the action message when the user presses the Return key and if it sends the message upon each keystroke (incremental search). You can also programmatically send the
setSendsWholeSearchString:
message to the search field’s cell.
You can also set other attributes inherited from NSSearchField
’s superclasses, such as:
Placeholder, which specifies text that appears in the search field until the user enters text. You can also programmatically send the
setPlaceholderString:
message to the search field’s cell.
Unless you’re using the Cocoa bindings Predicate
binding, you need to set the target and action of the search field (for more details see Implementing the Target). You can also connect a search field to a menu template. The details of the menu’s contents are described in Configuring a Search Menu.
Copyright © 2003, 2012 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2012-07-23