iOS中UIDatePicker的默认日期 [英] Default Date for UIDatePicker in iOS
问题描述
我是iOS开发的新手.我的故事板上有这个ViewController(包括一个UIDatePicker和一个条形按钮):
I am new in iOS development. I have this ViewController in my Storyboard (includes a UIDatePicker and a bar button):
我按照数据单元进行了调用我的DatePicker.当用户单击页面上的按钮PickerDate时,在导航栏上弹出带有完成栏的按钮:
I followed Data Cell to call my DatePicker. When user click on a button in the page PickerDate pops up with a done bar button on the navigation bar:
问题在于它仅将当前日期显示为 default
.当我从属性"中进行设置时,没有任何变化:
The problem is it shows just the current date as default
. Nothing changes when I set it from Properties:
您知道该如何解决吗?(通过设置属性
或以编程方式).
Do you know how can I fix it? (by setting up the properties
or programmatically).
推荐答案
我是通过编程方式完成的:
I did it programmatically in this way :
NSCalendar *calendar = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
NSDateComponents *components = [[[NSDateComponents alloc] init] autorelease];
[components setYear:1980];
[components setMonth:1];
[components setDay:1];
NSDate *defualtDate = [calendar dateFromComponents:components];
pickerView.date = defualtDate;
但是仍然不知道为什么通过设置属性
无法使用它.有帮助吗?
But still don't know why it doesn't work by setting up the properties
. Any help?
这篇关于iOS中UIDatePicker的默认日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!