我试图将UIPickerView添加到我的UITableViewController中,但它不允许我输入UIPickerViewDataSource。
我无法为选择器视图设置dataSource ......那么这将如何工作?
我收到此错误: 无法分配类型' TheTableViewController'输入' UIPickerViewDataSource?'
我已经全神贯注地寻找解决方案但无法找到它。谢谢!
我在
中有这段代码// The number of columns of data
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}
// The number of rows of data
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return pickerData.count
}
// The data to return for the row and component (column) that's being passed in
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return pickerData[row]
}
它工作正常,直到我添加UIPickerDataSource。
答案 0 :(得分:1)
您需要确保符合UIPickerViewDataSource,并且所有必需的方法都具有完全正确的名称。
所以你需要改为:
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return pickerData.count
}