【问题标题】:iOS Wrong disclosure background in UITableViewCell on iPad with iOS9iOS 使用 iOS9 在 iPad 上的 UITableViewCell 中显示错误的背景
【发布时间】:2018-02-04 00:10:10
【问题描述】:

我有类似的问题,就像我描述的 here。我再次找不到其他隐藏设置。

我为我的表格视图单元格使用了披露指示器。在装有 iOS 10+ 的 iPhone/iPad 上工作,在装有 iOS 9 的 iPhone 上看起来还不错,但在装有 iOS 9 的 iPad 上就不行了。

我尝试为附件视图设置背景,但还是一样。

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "tableCell", for: indexPath) as! TablesTableViewCell
    cell.accessoryView?.backgroundColor = tableView.backgroundColor
    if let tablesTable = fetchedResultsController?.object(at: indexPath) {
        currentTableSession = TableSessionTable.getCurrentTableSession(table: tablesTable)
        cell.tableNameLabel.text = tablesTable.tableName
        print("cell.contant view")
        print(cell.contentView.backgroundColor)
        print("cell.accessory view")
        print(cell.accessoryView?.backgroundColor)
        print("tableview.background")
        print(tableView.backgroundColor)

根据打印,它是 nil:

cell.contant 视图可选(UIDeviceRGBColorSpace 0.976539 0.977373 0.915492 1) cell.accessory 视图为零
tableview.background 可选(UIDeviceRGBColorSpace 0.976539 0.977373 0.915492 1)

也试过这个:

tableView.cellForRow(at: indexPath)?.accessoryView?.backgroundColor = tableView.backgroundColor

同样的结果。

知道如何解决这个问题吗?

【问题讨论】:

    标签: ios uitableview ipad ios9 uiaccessoryview


    【解决方案1】:

    我找到了解决办法! 感谢 Claude31 在 Apple Developers 论坛上帮助我解决了这个问题。

    最后我发现这个问题可以通过初始化 backgroundView 和设置颜色来解决:

    let backgroundView = UIView()  
    backgroundView.backgroundColor = tableView.backgroundColor  
    cell.backgroundView = backgroundView
    

    有效!

    【讨论】:

      猜你喜欢
      • 2018-01-09
      • 2015-12-15
      • 1970-01-01
      • 2013-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-09
      相关资源
      最近更新 更多