iOS Developer Library — Prerelease

Developer

UIKit Framework Reference UIPickerViewDataSource Protocol Reference

Options
Deployment Target:

On This Page
Language:

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.

  • Called by the picker view when it needs the number of components.

    Declaration

    Swift

    func numberOfComponentsInPickerView(_ pickerView: UIPickerView) -> Int

    Objective-C

    - (NSInteger)numberOfComponentsInPickerView:(UIPickerView * nonnull)pickerView

    Parameters

    pickerView

    The picker view requesting the data.

    Return Value

    The number of components (or “columns”) that the picker view should display.

    Availability

    Available in iOS 2.0 and later.

  • Called by the picker view when it needs the number of rows for a specified component.

    Declaration

    Swift

    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int

    Objective-C

    - (NSInteger)pickerView:(UIPickerView * nonnull)pickerView numberOfRowsInComponent:(NSInteger)component

    Parameters

    pickerView

    The picker view requesting the data.

    component

    A zero-indexed number identifying a component of pickerView. Components are numbered left-to-right.

    Return Value

    The number of rows for the component.

    Availability

    Available in iOS 2.0 and later.