In my storyboard, I set my table view controller's background color to the "default" setting, which shows up as white in interface builder. However, when I run the app, the table view controller's background color is black.
This seems to be a bug in Apple's code.
Steps to reproduce:
If you look at the xml file, you see something interesting. Dropping a brand new table view controller onto a storyboard will show the "[white] Default" option selected in the storyboard, however the xml will have a background color entry: <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
. This is peculiar because usually when something is set to its default value, it will be excluded from the xml file.
In Interface Builder, if you reselect the "[white] Default" option again, you will notice that the background color behind transparent views (eg the section header) will appear to change slightly. This is because even though the "[white] Default" option is shown as being selected, it has actually removed the <color>
entry in the xml file. Normally, this should select the default background color for the view. In this case, it chooses black. The Interface Builder UI is now no longer in sync with the xml file.
In Interface Builder, if you now select the "[white] White Color" option, the interface will show "[white] Default", and everything will be back to how it was when you originally dropped the table view controller on the storyboard.
This means that Interface Builder shows "[white] Default" for both when black and white are the selected options. The only way to know which is selected is at runtime, or by paying attention to subtle differences to transparent views in Interface Builder.
Therefore, in order to solve this problem, don't choose the "[white] Default" option in the background color setting, choose the "[white] White Color" option.
Selecting this:
... will show this:
... but the table view will appear like this: (buggy behavior)
On the other hand, selecting this:
... will show this:
... and the table view will appear like this: (correct behavior)
For changing the background color try to nil out the backgroundView property and then set the backgroundColor on the desired table view.
Try to use this:
[self.tableView setBackgroundView:nil];
[self.tableView setBackgroundColor:[UIColor whiteColor]];
Hope this can help you.
我在xcode-7-beta中遇到了同样的问题,发现的唯一“解决方法”是将TableView样式从Plain
切换为Grouped
。
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.