(1)设置代理
override func awakeFromNib() {
super.awakeFromNib()
self.pickerView.delegate = self
self.pickerView.dataSource = self
}
(2)遵循代理方法
//MARK: - UIPickerViewDelegate,UIPickerViewDataSource
extension YearPickerAlertView: UIPickerViewDelegate,UIPickerViewDataSource {
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return self.dataSource?.count ?? 0
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return self.dataSource![row]
}
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
self.selectedRow = row
}
}
网友评论