[Previous] [Protocol List] [Next]

NSComboBoxDataSource


Adopted by: NSObject (Informal Protocol)
Declared in: AppKit/NSComboBox.h


Protocol Description


The NSComboBoxDataSource category declares the methods that an NSComboBox uses to access the contents of its data source object. The combo box determines how many items to display by sending a numberOfItemsInComboBox: message, and accesses individual values with the comboBox:objectValueForItemAtIndex: method. Incremental searches-performed when a user types into the combo box's text field while the pop-up list is displayed-are performed by sending comboBox:indexOfItemWithStringValue: messages to the combo box's data source.

The NSComboBox treats objects provided by its data source as values to be displayed in the combo box's pop-up list. If these objects aren't of common value classes-such as NSString, NSNumber, and so on-you'll need to create a custom NSFormatter to display them. See the NSFormatter class specification for more information.

When an NSComboBoxDataSource is asked to supply a data item, the NSComboBox that sends the request is provided as a parameter. This allows a single data source object to manage several sets of data, choosing the appropriate set based on the identify of the NSComboBox that sends the message.



Protocol Methods



comboBox:indexOfItemWithStringValue:

- (unsigned int)comboBox:(NSComboBox *)aComboBox indexOfItemWithStringValue:(NSString *)aString

An NSComboBox uses this method to perform incremental-or "smart"-searches when the user types into the text field with the pop-up list displayed. Your implementation of this method should return the index for the item that matches aString, or NSNotFound if no item matches. This method is optional; if you don't provide an implementation for this method, no searches occur.

comboBox:objectValueForItemAtIndex:

- (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(int)index

Implement this method to return the object that corresponds to the item at index in aComboBox. Your data source must implement this method.

numberOfItemsInComboBox:

- (int)numberOfItemsInComboBox:(NSComboBox *)aComboBox

Implement this method to return the number of items managed for aComboBox by your data source object. An NSComboBox uses this method to determine how many items it should display in its pop-up list. Your data source must implement this method.


[Previous] [Next]