开发者

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"];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜