UIPickerView

2018-09-22  本文已影响0人  古月思吉

(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
    }
    
}
上一篇下一篇

猜你喜欢

热点阅读