0

I am using UIDatePicker to select a date. When loading the view date picker minimum date was set with current date, For my specification I need to know is there any modification done in UIDatePicker or not.

if ([[date_picker minimumDate] compare:[date_picker date]] != NSOrderedSame) {
  printf("value modified");
}

I have tried with the above condition but its always not matching even though I have not modified the date. Am I doing anything wrong? How do I find that out?

Newbee
  • 3,231
  • 7
  • 42
  • 74

1 Answers1

1

Set control events for datepicker like this

   [date_picker addTarget:self
               action:@selector(pickerChanged:)
     forControlEvents:UIControlEventValueChanged];

and in the pickerChanged method get its value

    - (void)pickerChanged:(id)sender{
             selectedDate=[sender date];
       }

date comparison with

    if ([initialDate compare:selectedDate]!=NSOrderedSame)
        {
           NSLog(@"modified");
         // two dates are same and the date formatting of the two dates must be same
        }

so whenever you change the date this method will be triggered initialDate is when the view loaded the value is set

Lochana Ragupathy
  • 4,320
  • 2
  • 25
  • 36