How to remember and load selected date in UIDatePicker?

匿名 (未验证) 提交于 2019-12-03 01:00:01

问题:

I have a UIDatePicker that well, allows you to select a date (not time). I then save this NSDate and use display it in a label on a different view. However, when I load back the view with the UIDatePicker, if the user has already selected a date, I want it to show that selected date (using NSDefaultPrefs). How do I do this?

I know how to do it for a normal UIPickerView, but how does it work if it is a date?

Thanks.

回答1:

You save and restore the date however you want (in a DB, NSDefaults, etc). Once you have the date you want to set it to you just call -[UIDatePicker setDate:animated:], so something like this:

- (void)viewDidLoad {   [super viewDidLoad];   [datePicker setDate:myDate animated:NO]; } 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!