March 2013
Intermediate to advanced
1000 pages
34h 51m
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:attributedTitleForRow:forComponent: (new in iOS 6)
pickerView:viewForRow:forComponent:reusingView: (delegate)
0. You can supply a simple string, an attributed string (Chapter 23), or an entire view such as a UILabel; but you should supply every row of every component the same way. 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 the code for a UIPickerView ...
Read now
Unlock full access