UIDataPicker进入TextField

时间:2016-05-26 13:41:32

标签: swift uitextfield datapicker

我将UIDataPicker的代码写入TextField

@IBOutlet weak var dateTextField: UITextField!


    @IBAction func textFieldEditing(sender: UITextField) {

        let datePickerView:UIDatePicker = UIDatePicker()
        datePickerView.datePickerMode = UIDatePickerMode.Date
        sender.inputView = datePickerView
        datePickerView.addTarget(self, action: ViewController.datePickerValueChanged, forControlEvents: UIControlEvents.ValueChanged)

    }

    func datePickerValueChanged(sender:UIDatePicker) {
        let dateFormatter = NSDateFormatter()
        dateFormatter.dateStyle = NSDateFormatterStyle.MediumStyle
        dateFormatter.timeStyle = NSDateFormatterStyle.NoStyle
        dateTextField.text = dateFormatter.stringFromDate(sender.date)
    }

但我有这个错误:

  

类型'ViewController'没有成员'datePickerValueChanged'

如何解决此错误?

1 个答案:

答案 0 :(得分:2)

dataPickerValueChanged or datePickerValueChanged?

检查您的代码