Protocol: UIPickerViewDelegate

Overview

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.Called by the picker view when it needs the styled title to use for a given row in a given component.Called by the picker view when the user selects a row in a component.Called by the picker view when it needs the row height to use for drawing row content.Called by the picker view when it needs the title to use for a given row in a given component.Called by the picker view when it needs the view to use for a given row in a given component.Called by the picker view when it needs the row width to use for drawing row content.

Instance Method Summary (collapse)

Instance Method Details

- (NSAttributedString) pickerView(pickerView, attributedTitleForRow:row, forComponent:component)

Called by the picker view when it needs the styled title to use for a given row in a given component. If you implement both this method and the pickerView:titleForRow:forComponent: method, the picker view prefers the use of this method. However, if your implementation of this method returns nil, the picker view falls back to using the string returned by the pickerView:titleForRow:forComponent: method.

Parameters:

  • pickerView (UIPickerView)

    An object representing the picker view requesting the data.

  • row (Integer)

    A zero-indexed number identifying a row of component. Rows are numbered top-to-bottom.

  • component (Integer)

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

Returns:

  • (NSAttributedString)

    The attributed string to use as the title of the indicated component row.

- (Object) pickerView(pickerView, didSelectRow:row, inComponent:component)

Called by the picker view when the user selects a row in a component. To determine what value the user selected, the delegate uses the row index to access the value at the corresponding position in the array used to construct the component.

Parameters:

  • pickerView (UIPickerView)

    An object representing the picker view requesting the data.

  • row (Integer)

    A zero-indexed number identifying a row of component. Rows are numbered top-to-bottom.

  • component (Integer)

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

Returns:

- (Float) pickerView(pickerView, rowHeightForComponent:component)

Called by the picker view when it needs the row height to use for drawing row content.

Parameters:

  • pickerView (UIPickerView)

    The picker view requesting this information.

  • component (Integer)

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

Returns:

  • (Float)

    A float value indicating the height of the row in points.

- (String) pickerView(pickerView, titleForRow:row, forComponent:component)

Called by the picker view when it needs the title to use for a given row in a given component. If you implement both this method and the pickerView:attributedTitleForRow:forComponent: method, the picker view prefers the pickerView:attributedTitleForRow:forComponent: method. However, if that method returns nil, the picker view falls back to using the string returned by this method.

Parameters:

  • pickerView (UIPickerView)

    An object representing the picker view requesting the data.

  • row (Integer)

    A zero-indexed number identifying a row of component. Rows are numbered top-to-bottom.

  • component (Integer)

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

Returns:

  • (String)

    The string to use as the title of the indicated component row.

- (UIView) pickerView(pickerView, viewForRow:row, forComponent:component, reusingView:view)

Called by the picker view when it needs the view to use for a given row in a given component. If the previously used view (the view parameter) is adequate, return that. If you return a different view, the previously used view is released. The picker view centers the returned view in the rectangle for row.

Parameters:

  • pickerView (UIPickerView)

    An object representing the picker view requesting the data.

  • row (Integer)

    A zero-indexed number identifying a row of component. Rows are numbered top-to-bottom.

  • component (Integer)

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

  • view (UIView)

    A view object that was previously used for this row, but is now hidden and cached by the picker view.

Returns:

  • (UIView)

    A view object to use as the content of row. The object can be any subclass of UIView, such as UILabel, UIImageView, or even a custom view.

- (Float) pickerView(pickerView, widthForComponent:component)

Called by the picker view when it needs the row width to use for drawing row content.

Parameters:

  • pickerView (UIPickerView)

    The picker view requesting this information.

  • component (Integer)

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

Returns:

  • (Float)

    A float value indicating the width of the row in points.