mardi 24 mars 2015

UIDatePicker's Value Changed Event Isn't Triggered When Value Is Changed For the First Time

I use Swift to develop a iOS app. I have a text field on storyboard and need to set UIDatePicker as its input view. The following is my code.



@IBOutlet var textField: UITextField!

override func viewDidLoad() {
super.viewDidLoad()
var datePicker: UIDatePicker = UIDatePicker()
datePicker.datePickerMode = UIDatePickerMode.CountDownTimer
datePicker.addTarget(self, action: "datePickerValueChanged:", forControlEvents: UIControlEvents.ValueChanged)
textField.inputView = datePicker
}

@IBAction func datePickerValueChanged(sender: UIDatePicker) {
println("Event is triggered.")
}


When I run the app and change value for the first time, ValueChanged event isn't triggered. When I change value for the second time, the event is triggered.


If I comment code datePicker.datePickerMode = UIDatePickerMode.CountDownTimer, the event will be triggered when value is changed for the first time.


I need to customize UIDatePickerMode to CountDownTimer. I also need to make sure the event is triggered when value is changed for the first time. How can I fix this issue?


Thank you.




Aucun commentaire:

Enregistrer un commentaire