Hi, this question is only about for curiosity.
I have UIPickerView in my controller, delegate is bound from IB and implemented in controller, and also one of UIPickerViewDataSource method is implemented in controller numberOfRowsInComponent. This method get called even dataSource is not bound and implemented completely. I wonder how it's possible? One of my thought is, this method called from background implicitly... My code;
class ViewController: UIViewController, UIPickerViewDelegate {
let titles = ["item 1", "item 2", "item 3", "item 4", "item 5"]
override func viewDidLoad() {
super.viewDidLoad()
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return titles.count
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return titles[row]
}
As you have mentioned in your comment that you have set
delegate
/datasource
fromstoryboard
, then its equivalent topickerView.delegate = self
/pickerView.datasource = self
.You can assign
delegate
anddatasource
either by coding or from storyboard. So in your case you have done it fromstoryboard
, so its actually bound with yourpickerView
.