UIDatePicker issues in popovers on iOS 8

五迷三道 提交于 2020-01-12 04:51:05

问题


Is anyone else having issues with UIDatePickers in popovers on iOS 8? Suddenly our date pickers are not showing up correctly (see screenshot). It appears that part of the picker is not being displayed (though, you can still interact with the missing portion to change the time).

I did some testing, and date pickers display perfectly in other views, so it's something related to either popovers or displaying the pickers in a view that is not full screen.

Has anyone found a fix or a workaround for these issues?


回答1:


I found a solution in the Apple Developer Forums (my backup knowledge base when Stack Overflow fails me).

User Natsu had the following solution:

I have the same problem in my project. And it causes only on iPad devices (iPhone has no problem with same code). As my understanding, UIDatePicker contains UITableView and UITableViewCell for displaying picker contents and its background color is set white as default. This is the reason of this issue. iOS 7 has UITableViewCell with white background in UIDatePicker iOS 8 has UITableView with white background in UIDatePicker So my solution is that I set these background color to nil by using UIAppearance like this:

[[UITableView appearanceWhenContainedIn:[UIDatePicker class], nil] setBackgroundColor:nil]; // for iOS 8
[[UITableViewCell appearanceWhenContainedIn:[UIDatePicker class], [UITableView class], nil] setBackgroundColor:[UIColor colorWithWhite:0.0 alpha:0.0]]; // for iOS 7

The values I set are the color used on iPhone. I'm not sure that it's a correct way to fix the issue. But at least in my environment it works well. I don't know if the problem of UIPickerView causes by same reason. But checking view hierarchy may help you.

Since this uses UIAppearance you can put it almost anywhere. I put it in awakeFromNib in my table cell class and it worked like a charm. Thanks Natsu!



来源:https://stackoverflow.com/questions/25916124/uidatepicker-issues-in-popovers-on-ios-8

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