我需要一些帮助。我一直在寻找解决方案两天。
class Mam_sEntre_eViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate {
let notes = [0, 1, 2, 3, 4, 5]
@IBOutlet weak var noteGoutPickerView: UIPickerView!
@IBAction func validate() {
validateNoteMam_sEntre_e()
}
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return notes.count
}
private func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> Int? {
return notes[row]
}
private func validateNoteMam_sEntre_e() {
let noteGoutIndex = noteGoutPickerView.selectedRow(inComponent: 0)
let noteGout = notes[noteGoutIndex]
}
}
答案 0 :(得分:0)
更改
private func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> Int? {
return notes[row]
}
收件人
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return String(notes[row])
}
不是私有的,返回String不是Int。参见https://developer.apple.com/documentation/uikit/uipickerviewdelegate/1614384-pickerview