Observing change in UIDatePicker

Chris picture Chris · Aug 8, 2012 · Viewed 27.9k times · Source

I noticed that there is no delegate to observe changes in UIDatePicker. Is there a way to detect when a change is made in the picker without confirming anything, like the moment it spins and lands on a new number I want to be able to detect that. I thought about key value observing, but I don't think there's a property that changes on the spot

Answer

chroman picture chroman · Aug 8, 2012

You need to add to your UIDatePicker the UIControlEventValueChanged event to handle date changes:

[myDatePicker addTarget:self action:@selector(dateIsChanged:) forControlEvents:UIControlEventValueChanged];

Then the implementation:

- (void)dateIsChanged:(id)sender{
     NSLog(@"Date changed");
}