Search code examples
iphoneobjective-cuidatepicker

UIDatePicker upon date changed


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?


Solution

  • 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
    }