开发者

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

开发者 https://www.devze.com 2023-04-03 18:28 出处:网络
I am using Xcode 4. I have DatePicker Component. It is taking the Default date which is set in IB\'s Date

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...

 开发者_JAVA百科- (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]
    }

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


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.


Try this in viewWillAppear rather than viewDidLoad. Also, ensure ddlDatePicker is not nil:

NSLog(@"%@", ddlDatePicker);
0

精彩评论

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