I have an application in which I ask users for their birthday using UIDatePicker, and then saved it in the standard user standards. When the application opens again, I get the date again, and then I want to set the UIDatePicker to this date, but it crashes and does not accept the date. It is stored in the format "June 8, 2009."
How can I do it? Here's how I do it now:
- (void)viewWillAppear:(BOOL)animated {
birthDate = [Preferences getBirthDate];
if (birthDate == nil) {
[datePicker setDate:[NSDate date] animated:NO];
}
}
My custom pref methods look like this in their class:
+ (NSDate *)getBirthDate {
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"DOB"])
return [[NSUserDefaults standardUserDefaults] objectForKey:@"DOB"];
else {
return nil;
}
}
+ (BOOL)setBirthDate:(NSDate *)bDate {
[[NSUserDefaults standardUserDefaults] setObject:bDate forKey:@"DOB"];
return [[NSUserDefaults standardUserDefaults] synchronize];
}
Thanks in advance.
source
share