Radu Paise Radu Paise - 3 months ago 38
Objective-C Question

empty NSDatePicker

Is it possible to have a NSDatePicker representing a nil object? Something like -/-/- or any other way.



Short answer: No

NSDatePicker simply ignores invalid dates and nil.
For example, this does not update the NSDatePicker, the old value remains:

[datePicker setDateValue:nil];

Only solution: Detect nil and do something specific:

if(date == nil) {

    // Set Specific Date
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"yyyyMMdd"];
    NSDate *nilDate = [dateFormat dateFromString:@"20000101"];  
    [datePicker setDateValue:nilDate];

    // Or Disable
    [datePicker setEnabled:FALSE];

} else {

    // Update Date
    [datePicker setDateValue:date];