Class

UIPickerView

A view that uses a spinning-wheel or slot-machine metaphor to show one or more sets of values.

Overview

The user interface provided by a picker view consists of components and rows. A component is a wheel, which has a series of items (rows) at indexed locations on the wheel. Each component also has an indexed location (left to right) in a picker view. Each row on a component has content, which is either a string or a view object such as a label (UILabel) or an image (UIImageView). Users select values by rotating the wheels so that the desired row of values aligns with a selection indicator.

Note that the UIDatePicker class uses a custom subclass of UIPickerView to display dates and times. To see an example, tap the add (“+”) button in the Alarm pane of the Clock app.

Topics

Providing the Picker Data

var dataSource: UIPickerViewDataSource?

The data source for the picker view.

protocol UIPickerViewDataSource

The UIPickerViewDataSource protocol must be adopted by an object that mediates between a UIPickerView object and your application’s data model for that picker view. The data source provides the picker view with the number of components, and the number of rows in each component, for displaying the picker view data. Both methods in this protocol are required.

Customizing the Picker Behavior

var delegate: UIPickerViewDelegate?

The delegate for the picker view.

protocol UIPickerViewDelegate

The delegate of a UIPickerView object must adopt this protocol and implement at least some of its methods to provide the picker view with the data it needs to construct itself.

Getting the Dimensions of the View Picker

var numberOfComponents: Int

Gets the number of components for the picker view.

func numberOfRows(inComponent: Int)

Returns the number of rows for a component.

func rowSize(forComponent: Int)

Returns the size of a row for a component.

Reloading the View Picker

func reloadAllComponents()

Reloads all components of the picker view.

func reloadComponent(Int)

Reloads a particular component of the picker view.

Selecting Rows in the View Picker

func selectRow(Int, inComponent: Int, animated: Bool)

Selects a row in a specified component of the picker view.

func selectedRow(inComponent: Int)

Returns the index of the selected row in a given component.

Returning the View for a Row and Component

func view(forRow: Int, forComponent: Int)

Returns the view used by the picker view for a given row and component.

Managing the Appearance of the Picker View

var showsSelectionIndicator: Bool

A Boolean value that determines whether the selection indicator is displayed.

See Also

Content Views

class UIActivityIndicatorView

A view that shows that a task is in progress.

class UIImageView

An object that displays a single image or a sequence of animated images in your interface.

class UIProgressView

A view that depicts the progress of a task over time.

class UIWebView

A view that embeds web content in your app.