views:

1904

answers:

1

I have read other questions about creating a UIPickerView with two or more columns but cannot find the exact solution.

How is this done for the iPhone programmatically? How do you add static data? Thanks!

+2  A: 

Make your controller (or whatever is controlling the behavior of the PickerView) support the UIPickerViewDelegate protocol. Then, implement:

- (int) numberOfColumnsInPickerView:(UIPickerView*)picker

to return the number of columns you want, and

- (int) pickerView:(UIPickerView*)picker numberOfRowsInColumn:(int)col

to return the number of rows for each column, and finally:

- (UIPickerTableCell*) pickerView:(UIPickerView*)picker tableCellForRow:(int)row inColumn:(int)col

to setup each cell.

See the reference for UIPickerView and UIPickerViewDelegate.

A decent code example is here.

zpasternack