The code is very simple, actually it is a test case to be completed.
I connected the pickerView dataSource and delegate to the tableViewController on the graphic interface
The sequence of function call is:
numberOfSections
tableView(_ tableView: UITableView, numberOfRowsInSection)
tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath)
awakeFromNib()
The message "unrecognized selector sent to instance <id>" have the id of the TableViewController.
class TableViewController: UITableViewController
....
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cella", for: indexPath)
return cell
}
===============================================================
class TableViewCell: UITableViewCell, UIPickerViewDelegate, UIPickerViewDataSource
{
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 2
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return 5
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return "cucu"
}
@IBOutlet weak var picker: UIPickerView!
override func awakeFromNib() {
super.awakeFromNib()
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
}
class TableViewController: UITableViewController {
....
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cella", for: indexPath)
return cell
}
===============================================================
class TableViewCell: UITableViewCell, UIPickerViewDelegate, UIPickerViewDataSource
{
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 2
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return 5
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return "cucu"
}
@IBOutlet weak var picker: UIPickerView!
override func awakeFromNib() {
super.awakeFromNib()
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
}