blank UIDatePicker on iPad in mode UIDatePickerModeDateAndTime

怎甘沉沦 提交于 2019-12-31 02:51:11

问题


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];

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

Thanks a lot for your answers!


回答1:


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.




回答2:


The problem is with the line:

dtVCpicker.date = [NSDate date];

This causes the UIDatePicker with UIDatePickerModeDateAndTime to break (probably a bug). However, this line is needless, since the date picker is by default set to current date.

To sum up, in my code I simply solve the issue by removing the above line. Of course, it is still possible to set the date of the picker, but in the other method.



来源:https://stackoverflow.com/questions/7846534/blank-uidatepicker-on-ipad-in-mode-uidatepickermodedateandtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!