Search code examples
ipaduidatepickeruidatepickermodetime

blank UIDatePicker on iPad in mode UIDatePickerModeDateAndTime


I am struggling with the UIDatePicker on iPad. The setDate or .date assignment makes the DatePicker empty:

    UIDatePicker * dtVCpicker = [[UIDatePicker alloc] initWithFrame:CGRectZero]; 
    dtVCpicker.datePickerMode = UIDatePickerModeDateAndTime;
    dtVCpicker.date = [NSDate date];
    dtVCpicker.minimumDate = [NSDate date];
[self.view.window addSubview:dtVCpicker];

Here is how my DatePicker looks like on iPad

if I change the mode to UIDatePickerModeDate or UIDatePickerModeTime then it would look normal.

Thanks a lot for your answers!


Solution

  • I implemented the work-around for this issue: setting the dtVCpicker.date inside the viewDidLoad made the Picker displayable.


    In my existing code, I just added the picker inside a Popup, and so viewDidLoad wasn't called when the Popup displays. So I created a view that contains the picker, and put the view inside the Popup (and put the setDate in the viewDidLoad). It works.