Search code examples
iphoneuipickerview

Very simple iPhone question. How to make UIPickerView with two columns?


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!


Solution

  • 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.