NSSearchFieldCell Class Reference
| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/AppKit.framework |
| Availability | Available in OS X v10.3 and later. |
| Companion guide | |
| Declared in | NSSearchFieldCell.h |
Overview
The NSSearchFieldCell class defines the programmatic interface for text fields that are optimized for text-based searches. An NSSearchFieldCell object is “wrapped” by an NSSearchField control object, which directly inherits from the NSTextField class. The search field implemented by these classes presents a standard user interface for searches, including a search button, a cancel button, and a pop-up icon menu for listing recent search strings and custom search categories.
When the user types and then pauses, the cell’s action message is sent to its target. You can query the cell’s string value for the current text to search for. Do not rely on the sender of the action to be an NSMenu object because the menu may change. If you need to change the menu, modify the search menu template and call the setSearchMenuTemplate: method to update.
Tasks
Managing Buttons
-
– setSearchButtonCell: -
– searchButtonCell -
– resetSearchButtonCell -
– setCancelButtonCell: -
– cancelButtonCell -
– resetCancelButtonCell
Custom Layout
Managing Menu Templates
Managing Search Modes
-
– setSendsWholeSearchString: -
– sendsWholeSearchString -
– sendsSearchStringImmediately -
– setSendsSearchStringImmediately:
Managing Recent Search Strings
Instance Methods
cancelButtonCell
Returns the button cell object used to display the cancel-button image.
Return Value
The cancel button cell.
Availability
- Available in OS X v10.3 and later.
Declared In
NSSearchFieldCell.hcancelButtonRectForBounds:
Modifies the bounding rectangle for the cancel button cell.
Parameters
- rect
The current bounding rectangle for the cancel button.
Return Value
The updated bounding rectangle to use for the cancel button. The default value is the value passed into the rect parameter.
Discussion
Subclasses can override this method to return a new bounding rectangle for the cancel button cell. You might use this method to provide a custom layout for the search field control.
Availability
- Available in OS X v10.3 and later.
Declared In
NSSearchFieldCell.hmaximumRecents
Returns the maximum number of recent search strings to display in the custom search menu.
Return Value
The maximum number of search strings that can appear in the menu. This value is between 0 and 254.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSearchFieldCell.hrecentsAutosaveName
Returns the key under which the prior list of recent search strings has been archived.
Return Value
The autosave name, which is used as a key in the standard user defaults to save the recent searches. The default value is nil, which causes searches not to be autosaved.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSearchFieldCell.hrecentSearches
Returns the list of recent search strings for the control.
Return Value
An array of NSString objects, each of which contains a search string either displayed in the search menu or from a recent autosave archive. If there have been no recent searches and no prior searches saved under an autosave name, this array may be empty.
Availability
- Available in OS X v10.3 and later.
Declared In
NSSearchFieldCell.hresetCancelButtonCell
Resets the cancel button cell to its default attributes.
Discussion
This method resets the target, action, regular image, and pressed image. By default, when users click the cancel button, the delete: action message is sent up the responder chain to the first NSText object that can handle it. This method gives you a way to customize the cancel button for specific situations and then reset the button defaults without having to undo changes individually.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSearchFieldCell.hresetSearchButtonCell
Resets the search button cell to its default attributes.
Discussion
This method resets the target, action, regular image, and pressed image. By default, when users click the search button or press the Return key, the action defined for the receiver is sent to its designated target. This method gives you a way to customize the search button for specific situations and then reset the button defaults without having to undo changes individually.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSearchFieldCell.hsearchButtonCell
Returns the button cell used to display the search-button image.
Return Value
The search button cell.
Availability
- Available in OS X v10.3 and later.
Declared In
NSSearchFieldCell.hsearchButtonRectForBounds:
Modifies the bounding rectangle for the search button cell.
Parameters
- rect
The current bounding rectangle for the search button.
Return Value
The updated bounding rectangle to use for the search button. The default value is the value passed into the rect parameter.
Discussion
Subclasses can override this method to return a new bounding rectangle for the search button cell. You might use this method to provide a custom layout for the search field control.
Availability
- Available in OS X v10.3 and later.
Declared In
NSSearchFieldCell.hsearchMenuTemplate
Returns the menu template object used to dynamically construct the search pop-up icon menu.
Return Value
The current menu template.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSearchFieldCell.hsearchTextRectForBounds:
Modifies the bounding rectangle for the search-text field cell.
Parameters
- rect
The current bounding rectangle for the search text field.
Return Value
The updated bounding rectangle to use for the search text field. The default value is the value passed into the rect parameter.
Discussion
Subclasses can override this method to return a new bounding rectangle for the text-field cell object. You might use this method to provide a custom layout for the search field control.
Availability
- Available in OS X v10.3 and later.
Declared In
NSSearchFieldCell.hsendsSearchStringImmediately
Returns a Boolean value indicating whether the receiver sends its action immediately upon being notified of changes to the search field text or after a brief pause.
Return Value
YES if the cell sends its action immediately upon notification of any changes to the search field; otherwise, NO.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSSearchFieldCell.hsendsWholeSearchString
Returns a Boolean value indicating whether the receiver sends the search action message when the user clicks the search button (or presses return) or after each keystroke.
Return Value
YES if the action message is sent all at once when the user clicks the search button or presses return; otherwise, NO if the search string is sent after each keystroke. The default value is NO.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSearchFieldCell.hsetCancelButtonCell:
Sets the button cell object used to display the cancel-button image
Parameters
- cell
The cancel button cell.
Availability
- Available in OS X v10.3 and later.
Declared In
NSSearchFieldCell.hsetMaximumRecents:
Sets the maximum number of search strings that can appear in the search menu
Parameters
- maxRecents
The maximum number of search strings that can appear in the menu. This value can be between
0and254. Specifying a value less than0sets the value to the default, which is10. Specifying a value greater than254sets the maximum to254.
Discussion
When the limit is exceeded, the oldest search string on the menu is dropped.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSearchFieldCell.hsetRecentsAutosaveName:
Sets the autosave name under which the receiver automatically archives the list of recent search strings.
Parameters
- name
The autosave name, which is used as a key in the standard user defaults to save the recent searches. If you specify
nilor an empty string for this parameter, no autosave name is set and searches are not autosaved.
Availability
- Available in OS X v10.3 and later.
Declared In
NSSearchFieldCell.hsetRecentSearches:
Sets the list of recent search strings to list in the pop-up icon menu of the receiver.
Parameters
- searches
An array of
NSStringobjects containing the search strings.
Discussion
You might use this method to set the recent list of searches from an archived copy.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSearchFieldCell.hsetSearchButtonCell:
Sets the button cell used to display the search-button image
Parameters
- cell
The search button cell.
Availability
- Available in OS X v10.3 and later.
Declared In
NSSearchFieldCell.hsetSearchMenuTemplate:
Sets the menu template object used to dynamically construct the receiver's pop-up icon menu.
Parameters
- menu
The menu template to use.
Discussion
The receiver looks for the tag constants described in “Menu tags” to determine how to populate the menu with items related to recent searches. See “Configuring a Search Menu” for a sample of how you might set up the search menu template.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSearchFieldCell.hsetSendsSearchStringImmediately:
Sets whether the cell sends its action message to the target immediately upon notification of any changes to the search field text or after a brief pause.
Parameters
- flag
YESto send the cell's action immediately upon notification of any changes to the search field; otherwise,NOif you want the cell to pause briefly before sending its action message. Pausing gives the user the opportunity to type more text into the search field before initiating the search.
Availability
- Available in OS X v10.4 and later.
See Also
Declared In
NSSearchFieldCell.hsetSendsWholeSearchString:
Sets whether the receiver sends the search action message when the user clicks the search button (or presses return) or after each keystroke.
Parameters
- flag
YESto send the action message all at once when the user clicks the search button or presses return; otherwise,NOto send the search string after each keystroke.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSearchFieldCell.hConstants
Menu tags
The NSSearchFieldCell class uses these tag constants for identifying special menu items in the search-menu template set by setSearchMenuTemplate:. When an NSSearchFieldCell object dynamically constructs the actual search menu from this template, it shows or hides the tagged items as directed.
#define NSSearchFieldRecentsTitleMenuItemTag 1000 #define NSSearchFieldRecentsMenuItemTag 1001 #define NSSearchFieldClearRecentsMenuItemTag 1002 #define NSSearchFieldNoRecentsMenuItemTag 1003
Constants
NSSearchFieldRecentsTitleMenuItemTagIdentifies the menu item that is the title of the menu group for recent search strings.
This item is hidden if there are no recent strings.
You may use this tagged item for separator characters that also do not appear if there are no recent strings to display.
Available in OS X v10.3 and later.
Declared in
NSSearchFieldCell.h.NSSearchFieldRecentsMenuItemTagIdentifies where recent search strings should appear in the “recents” menu group.
Available in OS X v10.3 and later.
Declared in
NSSearchFieldCell.h.NSSearchFieldClearRecentsMenuItemTagIdentifies the menu item for clearing the current set of recent string searches in the menu.
This item is hidden if there are no recent strings.
Available in OS X v10.3 and later.
Declared in
NSSearchFieldCell.h.NSSearchFieldNoRecentsMenuItemTagIdentifies the menu item that describes a lack of recent search strings (for example, “No recent searches”).
This item is hidden if there have been recent searches.
Available in OS X v10.3 and later.
Declared in
NSSearchFieldCell.h.
Availability
- Available in OS X v10.3 and later.
Declared In
NSSearchFieldCell.h© 2008 Apple Inc. All Rights Reserved. (Last updated: 2008-03-11)