我在用户选择日期时尝试使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)

}

最佳答案

DatePicker具有自己的属性以响应更改事件。
https://developer.apple.com/reference/uikit/uicontrolevents/1618238-valuechanged

关于swift - Swift选择器-无法识别的选择器已发送到实例(UIDatePicker),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40085267/

10-13 06:35