tableView单元格中的披露指示未显示

时间:2019-11-28 08:51:20

标签: swift xcode uitableview cell

我在cell.accessoryType = .disclosureIndicator委托中添加了cellForRowAt,并且还在“附件”下的viewController UI选项中打了勾。我还为tableView添加了边距,以使其相对于父视图(即设备)为0。

我甚至设置了cell.accessoryView?.tintColor = UIColor.black,以防颜色有问题。但是,我仍然看不到单元格右侧的小箭头。我正在使用默认的cell。在我拥有的其他viewControllers中,它起作用了,但在这一点却没有。

我检查了单元格和表格视图的宽度,它们均为375。

如果我改为添加自定义图片,它确实可以正常工作,

let img = UIImage.init(named: "arrow")
cell.accessoryView = UIImageView.init(image: img)

但是,我想要标准箭头。

关于这里可能有什么问题的其他提示?

1 个答案:

答案 0 :(得分:0)

如果您以iOS 13为目标,则此操作将无效。您可以在iOS12上进行验证,但今年早些时候我遇到了这个问题,解决方案是在单元格中添加UIButton,将其限制在屏幕尾部。

         let disclosureButton = UIButton()
        disclosureButton.setImage(UIImage(named: "arrow"), for: .normal)
        cell.addSubview(disclosureButton)
        disclosureButton.translatesAutoresizingMaskIntoConstraints = false
        disclosureButton.trailingAnchor.constraint(equalTo: cell.trailingAnchor, constant: -10).isActive = true
        disclosureButton.centerYAnchor.constraint(equalTo: cell.centerYAnchor, constant: 0).isActive = true
        disclosureButton.widthAnchor.constraint(equalToConstant: 25).isActive = true
        disclosureButton.heightAnchor.constraint(equalToConstant: 25).isActive = true