Class

NSComboBox

A view that displays a list of values in a pop-up menu where the user selects a value or types in a custom value.

Declaration

@interface NSComboBox : NSTextField

Overview

A combo box combines the behavior of an NSTextField object with an NSPopUpButton object. A combo box displays a list of values from a pop-up list, but also provides a means for users to type in custom values. Figure 1 shows a combo box in its initial state:

Clicking in the text portion of the control allows the user to edit the current value. When the user clicks the down arrow at the right side of the text field, the pop-up list appears, as shown in Figure 2:

The NSComboBox class uses NSComboBoxCell to implement its user interface.

Also see the NSComboBoxDataSource protocol, which declares the methods that NSComboBox uses to access the contents of its data source object.

Topics

Setting Display Attributes

hasVerticalScroller

A Boolean value indicating whether the combo box has a vertical scroller.

intercellSpacing

The horizontal and vertical spacing between cells in the pop-up list.

buttonBordered

A Boolean value indicating whether the combo box displays a border.

itemHeight

The height of each item in the pop-up list.

numberOfVisibleItems

The maximum number of visible items to display in the pop-up list at one time.

Setting a Data Source

dataSource

The object that provides the item data for the combo box.

usesDataSource

A Boolean value indicating whether the combo box retrieves its items from a data source object.

Configuring the Combo Box Items

- addItemsWithObjectValues:

Adds multiple objects to the end of the receiver’s internal item list.

- addItemWithObjectValue:

Adds an object to the end of the receiver’s internal item list.

- insertItemWithObjectValue:atIndex:

Inserts an object at the specified location in the receiver’s internal item list.

objectValues

An array of the items from the combo box’s internal list.

- removeAllItems

Removes all items from the receiver’s internal item list.

- removeItemAtIndex:

Removes the object at the specified location from the receiver’s internal item list.

- removeItemWithObjectValue:

Removes all occurrences of the given object from the receiver’s internal item list.

numberOfItems

The total number of items in the pop-up list.

Manipulating the Displayed List

- indexOfItemWithObjectValue:

Searches the receiver’s internal item list for the specified object and returns the lowest matching index.

- itemObjectValueAtIndex:

Returns the object located at the given index within the receiver’s internal item list.

- noteNumberOfItemsChanged

Informs the receiver that the number of items in its data source has changed.

- reloadData

Marks the receiver as needing redisplay, so that it will reload the data for visible pop-up items and draw the new values.

- scrollItemAtIndexToTop:

Scrolls the receiver’s pop-up list vertically so that the item at the specified index is as close to the top as possible.

- scrollItemAtIndexToVisible:

Scrolls the receiver’s pop-up list vertically so that the item at the specified index is visible.

Manipulating the Selection

- deselectItemAtIndex:

Deselects the pop-up list item at the specified index if it’s selected.

indexOfSelectedItem

The index of the last item selected from the pop-up list.

objectValueOfSelectedItem

The object corresponding to the last item selected from the pop-up list.

- selectItemAtIndex:

Selects the pop-up list row at the given index.

- selectItemWithObjectValue:

Selects the first pop-up list item that corresponds to the given object.

Completing the Text Field

completes

A Boolean value indicating whether the combo box tries to complete what the user types.

Accessing the Delegate

delegate

Sets the receiver’s delegate.

Notifications

NSComboBoxSelectionDidChangeNotification

Posted after the pop-up list selection of the NSComboBox changes.

NSComboBoxSelectionIsChangingNotification

Posted whenever the pop-up list selection of the NSComboBox is changing.

NSComboBoxWillDismissNotification

Posted whenever the pop-up list of the NSComboBox is about to be dismissed.

NSComboBoxWillPopUpNotification

Posted whenever the pop-up list of the NSComboBox is going to be displayed.

Relationships

Inherits From