33

昨晚我决定升级到 Xcode 5 并查看我当前的项目。将我的故事板更新到新的 UI 后,一切看起来都很棒并且运行良好。由于我有一个通用二进制文件,我决定在 iPad 上也进行测试,并注意到我的 UITableview 中引入了一个新的白色背景,那里曾经是透明/清晰的颜色。这似乎发生在单元格级别,而不是表格级别。当我在 6.1 模拟器上运行时,iPad 和 iPhone 上的一切看起来都很好。在 iOS7 的 iPhone 上一切看起来都很好。

我为界面生成器设置的所有内容对于 iPhone 和 iPad 都是相同的。据我所知,它与这个不尊重透明值/设置的新“内容视图”(它是项目单元格的子组)有关。

有什么想法/想法吗?

4

4 回答 4

103

在使用界面构建器浪费了多个小时之后,我认为那里可能存在错误。所以我开始寻找一个程序化的答案。显然,如果我从这里开始,我可以节省大量时间。通过添加到方法:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

通过添加这一行,我能够解决 iPad 上的透明度问题:

cell.backgroundColor = [UIColor clearColor];  // Adding this fixes the issue for iPad

希望这可以帮助其他所有人看到带有表格和 iOS7 的 ipad 的白色背景!

于 2013-09-19T20:55:23.827 回答
4

如果您使用自定义 UITableViewCell 并从 storyboard/xib 调用它,您可以使用以下代码。

@implementation YourCustomTableViewCell

- (void) awakeFromNib
{
    self.backgroundColor = [UIColor clearColor];
}
于 2014-10-10T07:51:20.430 回答
3

如果其他人仍然在 iPad 上的表格视图/单元格透明度方面遇到问题,这可能会有所帮助(从https://stackoverflow.com/a/31396483/2301213复制,自从他们改变的时候就很快了)

似乎在向窗口添加 UITableView 的过程中(在 willMoveToWindow 和 didMoveToWindow 之间),某些 iPad 将 table view 的 backgroundColor 重置为白色。它在不使用 backgroundColor 属性的情况下秘密地执行此操作。

当我需要彩色/透明表格时,我现在将其用作 UITableView 的基类...

class ColorableTableView : UITableView {
    var _backgroundColor:UIColor?
    override var backgroundColor:UIColor? {
        didSet {
            _backgroundColor = backgroundColor
        }
    }
    override func didMoveToWindow() {
        backgroundColor = _backgroundColor
        super.didMoveToWindow()
    }
}

单元格的背景颜色在我的 iPad 上也以相同的方式设置为白色(即在移动到窗口期间位于表格中的单元格),因此这同样适用于它们,以免最终出现奇怪的不透明单元格从不时重复使用...

class ColorableTableViewCell : UITableViewCell {
    var _backgroundColor:UIColor?
    override var backgroundColor:UIColor? {
        didSet {
            _backgroundColor = backgroundColor
        }
    }
    override func didMoveToWindow() {
        backgroundColor = _backgroundColor
        super.didMoveToWindow()
    }
}
于 2015-07-14T02:45:33.613 回答
0

如果您使用的是静态单元格表​​。您可以执行以下操作:

override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {

     cell.backgroundColor = UIColor.clearColor()
}
于 2015-05-10T13:47:22.597 回答