UIDatePicker upon date changed

Josh Kahane picture Josh Kahane · Sep 24, 2010 · Viewed 34.4k times · Source

I have just started using UIDatePicker in my iPad app, but is there a way of checking when the date has been changed?

I want to do something when the date is changed. What can I try?

Answer

Vladimir picture Vladimir · Sep 24, 2010

When properly configured, a UIDatePicker object sends an action message when a user finishes rotating one of the wheels to change the date or time; the associated control event is UIControlEventValueChanged.

so you need to add your class to handle UIControlEventValueChanged event in your picker:

[picker addTarget:self action:@selector(dateChanged:) 
              forControlEvents:UIControlEventValueChanged];
...

- (void) dateChanged:(id)sender{
   // handle date changes
}