May 2011
Beginner
834 pages
25h 19m
English
A UIPickerView displays selectable choices using a rotating drum metaphor. It has a standard legal range of possible heights, which is undocumented and must be discovered by trial and error (attempting to set the height outside this range will fail with a warning in the console); its width is largely up to you. Each drum, or column, is called a component.
Your code configures the UIPickerView’s content through its data source (UIPickerViewDataSource) and delegate (UIPickerViewDelegate), which are usually the same object (see also Chapter 11). Your data source and delegate must answer questions similar to those posed by a UITableView (Chapter 21):
numberOfComponentsInPickerView: (data source)
pickerView:numberOfRowsInComponent: (data source)
0.
pickerView:titleForRow:forComponent:
pickerView:viewForRow:forComponent:reusingView: (delegate)
0. You can supply either a simple title string or an entire view such as a UILabel, giving you more control over formatting, but you must supply every row of every component the same way, because if viewForRow is implemented, titleForRow isn’t called. The reusingView parameter, if not nil, is a view that you supplied for a row now no longer visible, giving you a chance to reuse it, much as cells are reused in a table view.
Here’s ...
Read now
Unlock full access