I have an app where I ask for the users birthday with a UIDatePicker then store it in standard user defaults. When the app is opened again I get the date again and then want to set the UIDatePicker to that date but it's crashing and not accepting the date. It's being stored in the format "June 8, 2009."
How do I need to do this? This is the way I'm trying it now:
- (void)viewWillAppear:(BOOL)animated {
birthDate = [Preferences getBirthDate];
if (birthDate == nil) {
[datePicker setDate:[NSDate date] animated:NO];
}
}
My user pref methods look like this in their class:
+ (NSDate *)getBirthDate {
// Geting via user defaults....
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"DOB"])
return [[NSUserDefaults standardUserDefaults] objectForKey:@"DOB"];
else {
return nil;
}
}
+ (BOOL)setBirthDate:(NSDate *)bDate {
//Setting via user defaults
[[NSUserDefaults standardUserDefaults] setObject:bDate forKey:@"DOB"];
return [[NSUserDefaults standardUserDefaults] synchronize];
}
Thanks in advance.