【发布时间】:2020-11-08 12:16:40
【问题描述】:
我有这个UITableViewCell:
我想要这样的结果:(请原谅我的错误编辑)
这意味着基本上将detail button的图像更改为另一个图像。
我当前的单元格代码
let cell = UITableViewCell(style: .default, reuseIdentifier: nil)
cell.textLabel?.text = NSLocalizedString("New", comment: "Add a new element")
cell.imageView?.image = UIImage(systemName: "plus.circle.fill")
cell.backgroundColor = .secondarySystemBackground
cell.imageView?.preferredSymbolConfiguration = .init(scale: UIImage.SymbolScale.large)
cell.selectionStyle = .none
cell.accessoryType = .detailButton
我尝试过的
我把它放在上面的代码之后。 (它不起作用)
for (i, view) in cell.subviews.enumerated() {
if view as? UIButton != nil {
(cell.subviews[i] as! UIButton).setImage(UIImage(systemName: "clock"), for: .normal) // Never executes
} else {
for (i, view) in view.subviews.enumerated() {
if view as? UIButton != nil {
(cell.subviews[i] as! UIButton).setImage(UIImage(systemName: "clock"), for: .normal) // Never executes
}
}
}
}
此代码在单元格的subviews 中搜索UIButton,如果找到,则更改其图像。但它永远找不到按钮!
查看层次结构
提前致谢。
【问题讨论】:
标签: swift uitableview uibutton