简体   繁体   中英

iOS Wrong disclosure background in UITableViewCell on iPad with iOS9

I have similar issue like I described here . And again I cannot find another hidden setting.

I used disclosure indicator for my table view cell. And working on iPhones/iPads with iOS 10+, iPhone with iOS 9 it looks fine, but not on iPad with iOS 9.

I have tried to set background for accessoryView, but it still the same.

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)

As per print, it's nil:

cell.contant view Optional(UIDeviceRGBColorSpace 0.976539 0.977373 0.915492 1) cell.accessory view nil
tableview.background Optional(UIDeviceRGBColorSpace 0.976539 0.977373 0.915492 1)

Also tried this:

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

Same result.

Any idea how to fix this?

在此处输入图片说明

在此处输入图片说明

I have found the solution! Thanks for Claude31 who helped me with with this issue on Apple Developers forum.

Finally I have found that the issue can be fixed by initializing backgroundView and setting colour:

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

It works!

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