UITableViewCell的accessoryView在iOS 13上具有灰色背景颜色。

5

我发现在iOS 13中,UITableViewCellaccessoryView具有灰色背景颜色,但在系统设置中它可以正常工作。

我已经尝试设置UITableView的背景颜色和色调颜色,但都没有起作用。

var cell = tableView.dequeueReusableCell(withIdentifier: "myInfo")
if (cell==nil) {
   cell = UITableViewCell.init(style: UITableViewCell.CellStyle.default, reuseIdentifier: "myInfo")
}

   cell!.accessoryType = .disclosureIndicator        

Xcode调试层次结构视图:

输入图像描述

原因似乎来自于系统的imageView:

输入图像描述


你是否将 cell.backgroundColor 设置为属性? - Harry J
@HarryJ 不是... - magic_9527
这可能不是问题的直接原因,但调用tableView.dequeueReusableCell(withIdentifier:)是错误的。正确的方法是tableView.dequeueReusableCell(withIdentifier:forIndexPath:)。这样你总是能得到一个单元格,而且不需要检查nil - matt
2个回答

6
我也注意到了这个问题。即使你将披露指标分配给accessoryView,该视图仍然返回nil。我一直在等待苹果修复这个问题,但似乎他们不会很快解决。因此,我创建了一个UITableViewCell的扩展来处理iOS13和之前的iOS版本。
extension UITableViewCell {
    func createCustomCellDisclosureIndicator(chevronColor: UIColor) {
        //MARK: Custom Accessory View
        //Chevron img
        if #available(iOS 13.0, *) {
            let chevronConfig = UIImage.SymbolConfiguration(pointSize: 14, weight: .medium)
            guard let chevronImg = UIImage(systemName: "chevron.right", withConfiguration: chevronConfig)?.withTintColor(chevronColor, renderingMode: .alwaysTemplate) else { return }
            let chevron = UIImageView(image: chevronImg)
            chevron.tintColor = chevronColor

            //chevron view
            let accessoryViewHeight = self.frame.height
            let customDisclosureIndicator = UIView(frame: CGRect(x: 0, y: 0, width: 15, height: accessoryViewHeight))
            customDisclosureIndicator.addSubview(chevron)

            //chevron constraints
            chevron.translatesAutoresizingMaskIntoConstraints = false
            chevron.trailingAnchor.constraint(equalTo: customDisclosureIndicator.trailingAnchor,constant: 0).isActive = true
            chevron.centerYAnchor.constraint(equalTo: customDisclosureIndicator.centerYAnchor).isActive = true

            //Assign the custom accessory view to the cell
            customDisclosureIndicator.backgroundColor = .clear
            self.accessoryView = customDisclosureIndicator
        } else {
            self.accessoryType = .disclosureIndicator
            self.accessoryView?.tintColor = chevronColor
        }
    }
}

我希望这可以帮到你。以下是两个模拟器的屏幕截图,其中一个运行iOS12.2,另一个运行iOS13。该应用程序名为七十二。

iOS12.2 vs. iOS13 屏幕截图


问题在发布的iOS 13中仍然存在。这个很有效。救了我的一天,谢谢! - Zoltan Vinkler

1

我在我的手机上遇到了同样的问题,我的解决方法是继承UITableViewCell,然后在accessoryView中使用自定义图像。

self.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_arrow"]];

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接