简体   繁体   中英

UITableView appearance setBackgroundColor not working for plain table styles when compiled on macOS High Sierra

I have successfully been using [[UITableView appearance] setBackgroundColor:[UIColor redColor]]; in didFinishLaunchingWithOptions for my iOS app under both Xcode 8 and 9 and macOS 10.12 (Sierra). This is with both simulator and phone hardware running iOS 11.

When I updated to 10.13, that code stopped functioning for any table view that isn't the "grouped" style. If I set the background color on a specific instance, then it works fine.

I have tried reinstalling Xcode, cleaning the build, verifying that I have no local changes from the source as built (and works) on other computers. Changing between the 10.3 and 11.0 SDKs also makes no difference.

According to Set UITableView BackgroundColor Universally with UIAppearance UITableView may not support this feature, but that answer is a few years old now and that this has been working for me seems to contradict it.

A good answer would explain what difference in my environment caused this problem.

The default background color for plain tables has evidently changed. Looking at the storyboard file, in Xcode 8.3.3 it generated this:

<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>

In Xcode 9 it changed to:

<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>

So this can be "fixed" by going to every table and resetting the background color to "default", but then your project won't work correctly in the other environment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM