为什么视图控制器不符合 UIPickerViewDataSource?
我已经检查了我能做的一切来从网络上调试它。
我已经为协议(Swift 3.1)输入了所有必要的功能,但徒劳无功。
这是我的代码:
class SelectClassViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {
let grades = ["7", "8", "9", "10", "11", "12"]
var selectCurrentGrade : String? = nil
@IBOutlet weak var Grade: UIPickerView!
@IBAction func Next(_ sender: Any) {
if selectCurrentGrade != nil {
performSegue(withIdentifier: "GradeToClass", sender: self)
}
}
@IBAction func Back(_ sender: Any) {
performSegue(withIdentifier: "GradeToMain", sender: self)
}
override func viewDidLoad() {
super.viewDidLoad()
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return grades[row]
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return grades.count
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
selectCurrentGrade = grades[row]
}
}
}