iPad 上处于 UIDatePickerModeDateAndTime 模式的空白 UIDatePicker
我在 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];
if I change the mode to UIDatePickerModeDate or UIDatePickerModeTime then it would look normal.
Thanks a lot for your answers!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我实现了此问题的解决方法:在 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.
问题在于该行:
这会导致带有 UIDatePickerModeDateAndTime 的 UIDatePicker 中断(可能是一个错误)。但是,这一行是不必要的,因为日期选择器默认设置为当前日期。
总而言之,在我的代码中,我只是通过删除上面的行来解决问题。当然,仍然可以设置选择器的日期,但是用另一种方法。
The problem is with the line:
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.