Swift选择器 - 发送到实例的无法识别的选择器(UIDatePicker)

时间:2016-10-17 11:31:32

标签: swift uidatepicker

当用户选择日期时,我在尝试让UIDatePicker工作时遇到问题。
我一直收到错误说:无法识别的选择器发送到实例。

 func textFieldDidBeginEditing(_ textField: UITextField) {
    let datePicker: UIDatePicker = UIDatePicker()
    datePicker.datePickerMode = UIDatePickerMode.date
    textField.inputView = datePicker
    datePicker.backgroundColor = UIColor.white
    datePicker.addTarget(self, action: Selector(("datePickerChanged:")), for: .valueChanged)

}




func datePickerChanged(sender: UIDatePicker){

    let formatter = DateFormatter()
    formatter.dateStyle = DateFormatter.Style.medium
    DEPtextField.text = formatter.string(from: sender.date)

}

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

如下更改功能

func datePickerChanged(_ sender: UIDatePicker){

    let formatter = DateFormatter()
    formatter.dateStyle = DateFormatter.Style.medium
    DEPtextField.text = formatter.string(from: sender.date)

}

应该可以。