I am using extensions here just so you can see which functions belong to which protocols.
(Swift 3)
class ViewController: UIViewController { @IBOutlet weak var picker: UIPickerView! var data: [String] = ["Row 1", "Row 2", "Row 3"] override func viewDidLoad() { super.viewDidLoad() picker.dataSource = self picker.delegate = self } } extension ViewController: UIPickerViewDataSource { // Like number of columns func numberOfComponents(in pickerView: UIPickerView) -> Int { return 1 } func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { return data.count } } extension ViewController: UIPickerViewDelegate { func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { return data[row] } }
(Swift 3)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.