iPad 上处于 UIDatePickerModeDateAndTime 模式的空白 UIDatePicker

发布于 2024-12-11 04:28:13 字数 432 浏览 0 评论 0原文

我在 iPad 上使用 UIDatePicker 时遇到了困难。 为

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

如果

我将模式更改 UIDatePickerModeDate 或 UIDatePickerModeTime 那么它看起来会正常。

非常感谢您的回答!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初心 2024-12-18 04:28:13

我实现了此问题的解决方法:在 viewDidLoad 内设置 dtVCpicker.date 使选取器可显示。


在我现有的代码中,我只是在 Popup 中添加了选择器,因此在 Popup 显示时不会调用 viewDidLoad 。因此,我创建了一个包含选择器的视图,并将该视图放入 Popup 中(并将 setDate 放入 viewDidLoad 中)。有用。

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.

み零 2024-12-18 04:28:13

问题在于该行:

dtVCpicker.date = [NSDate date];

这会导致带有 UIDatePickerModeDateAndTime 的 UIDatePicker 中断(可能是一个错误)。但是,这一行是不必要的,因为日期选择器默认设置为当前日期。

总而言之,在我的代码中,我只是通过删除上面的行来解决问题。当然,仍然可以设置选择器的日期,但是用另一种方法。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文