UIDatePicker + NSUserDefaults
I got an UIDatePicker and want to save its state (only shows hours) after a change. That works with:
myDate = [datePicker date];
NSUserDefaults *tableDefa开发者_如何学Cults = [NSUserDefaults standardUserDefaults];
tableDefaults setObject:myDate forKey:@"TheDate"];
So how can I get this back to my picker when i relaunch the app?
- (void)viewDidLoad {
if (myDate == nil) {
[datePicker setDate:[NSDate date] animated:NO];
} else {
[datePicker setDate:[myDate date] animated:NO];
}
}
Does not work for me, I just get the normal date / time.
Anyone who knows how to fix this? :(
Did you read myDate back out of NSUserDefaults, with code something like this:
NSUserDefaults *tableDefaults = [NSUserDefaults standardUserDefaults];
myDate = [tableDefaults objectForKey:@"TheDate"];
精彩评论