Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIDatePicker issues in popovers on iOS 8

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?

UIDatePicker issues in popovers on iOS 8

like image 702
Jeremy Avatar asked Sep 18 '14 14:09

Jeremy


1 Answers

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!

like image 89
Jeremy Avatar answered Oct 20 '22 16:10

Jeremy