美文网首页
UIPickerView

UIPickerView

作者: 古月思吉 | 来源:发表于2018-09-22 17:00 被阅读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
        }
        
    }
    

    相关文章

      网友评论

          本文标题:UIPickerView

          本文链接:https://www.haomeiwen.com/subject/hndxoftx.html