Search code examples
iphoneobjective-cxcodedatepickeruidatepicker

How can I set Date programmatically on Date Picker? setDate is not working?


I am using Xcode 4.

I have DatePicker Component.

It is taking the Default date which is set in IB's Date to highlight and select the date...

I want to set the current date in date picker to be selected...

Not working setDate Method...

 - (void)viewDidLoad
    {
        [super viewDidLoad];   

        [ddlDatePicker setDate:[NSDate date]];

        NSLog(@"-%@-",[NSDate date]);
     //NSLog is showing me the current date..Today's Date...
    //But ddlDatePicker is setted to the date on the day on which I created the date 
//Picker...Or You can say date field in the DatePicker's IB Properties.. 

    ![enter image description here][1]
    }

enter image description here


Solution

  • You have not connected with outlet your ddlDatePicker, so you haven't got reference to that object and couldn't manage it.

    Open IB and connect this UIDatePicker with your variable in appropriate controller.