Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default Date for UIDatePicker in iOS

I am new in iOS development. I have this ViewController in my Storyboard (includes a UIDatePicker and a bar button):

enter image description here

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:

enter image description here

The problem is it shows just the current date as default. Nothing changes when I set it from Properties:

enter image description here

Do you know how can I fix it? (by setting up the properties or programmatically).

like image 583
Ali Avatar asked May 10 '26 18:05

Ali


1 Answers

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?

like image 124
Ali Avatar answered May 12 '26 09:05

Ali