In this recipe, we will learn how to use the UIPickerView
class.
The UIPickerView
class provides us with a control whose functionality is similar to a listbox, specifically designed for human fingers touching the screen. Its main difference to a common listbox is that each column can have its own number of rows. To get started, create a new iPhone project and name it PickerViewApp
.
Open the
MainController.xib
file in Interface Builder.Add a
UILabel
and aUIPickerView
on the main View.Save the document.
Back in MonoDevelop, create a nested class in the
MainController
class that inherits fromUIPickerViewModel
:private class PickerModelDelegate : UIPickerViewModel
Add the following constructor and fields in the nested class:
public PickerModelDelegate (MainController controller) { this.parentController = controller; this.transportList = new List<string>() { "On foot", "Bicycle", "Motorcycle", "Car", "Bus" }; this.distanceList = new List...