I recently added a feature to my medical app that calculates a patient's age from an entered date. If the age is zero, then the date picker displays January 1, 1950 as a default starting date for entry of the date of开发者_StackOverflow中文版 birth. The code works fine on iOS 4.0+ on iPhone and iPad hardware. However, when testing just prior to submission for an app update, I found the date picker crashing on my first-generation iPod, which I keep for testing iOS 3.1.3. I narrowed down the following code as the culprit, which sets the default date for the date picker:
    if (age == 0) {
        NSDateFormatter *myFormatter = [[NSDateFormatter alloc] init];
        [myFormatter setDateFormat:@"M/d/yy"];
        NSDate *initialDate = [myFormatter dateFromString:@"January/01/1950"];
        [picker setDate:initialDate animated:YES];
    }
The log from the iPod shows the following two lines after the crash:
<Warning>: *** Assertion failure in -[UIDatePickerView _updateBitsForDate:andReload:animateIfNeeded:], /SourceCache/UIKit/UIKit-984.38/UIDatePicker.m:908
and
<Error>: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: date'
I would appreciate any help in understanding why this crash occurs only on the older device, and how to solve the issue. Thanks in advance.
According to the tr35-10 standard, your date format should be MMMM/dd/yyyy.
You should also cache formatters for efficiency.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论