[[NSUserDefaults standardUserDefaults] setObject:datePicker.date forKey:@"birthDate"];
[[NSUserDefaults standardUserDefaults] setInteger:sexSegmented.selectedSegmentIndex forKey:@"sex"];
[[NSUserDefaults standardUserDefaults] synchronize];
This is the value that I am saving to userdefaults and from another class I want to call them.
NSDate *birthDate = [[NSUserDefaults standardUserDefaults] objectForKey:@"birthDate"];
NSInteger a=[[NSUserDefaults standardUserDefaults] integerForKey:@"sex"];
NSLog(@"%@",birthDate);
[datePicker setDate:birthDate animated:YES];
sexSegmented.selectedSegmentIndex=a;
This is the other class from where I am get开发者_运维问答ting the saved values, but I can't see any value in birthDate. I want to take it and set the new datePicker to birthDate. Can anyone help me?
It's most likely a case of the interface outlet of datePicker
not being connected properly. This would make datePicker
nil
and as a result you would end up storing nil
in the user defaults.
You can validate this by doing
NSLog(@"%@", datePicker);
before your first snippet of code.
精彩评论