Ios 单元格高光显示默认图像,而不是实际图像
我在表格的单元格中有一个化身图像。当我触摸一个单元格(突出显示)时,它会显示默认的化身图像,而不是实际的图像。我不确定是什么原因造成的,以及如何修复。有什么帮助吗Ios 单元格高光显示默认图像,而不是实际图像,ios,swift,uitableview,Ios,Swift,Uitableview,我在表格的单元格中有一个化身图像。当我触摸一个单元格(突出显示)时,它会显示默认的化身图像,而不是实际的图像。我不确定是什么原因造成的,以及如何修复。有什么帮助吗 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { guard let cell = tableView.dequeueReusableCell(withIde
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "TableViewCell", for: indexPath) as? TableViewCell else {
fatalError("Can't find cell")
}
//...
cell.selectionStyle = .default
self.configCell(cell: cell, indexPath: indexPath)
//...
}
func configCell(cell: TableViewCell, indexPath: IndexPath) {
//...
// Avatar
if let url = URL(string: urlString) {
cell.avatarImageView.image = .defaultImage
cell.tag = indexPath.row
let task = URLSession.shared.dataTask(with: url) { data, response, error in
guard let data = data, error == nil else { return }
DispatchQueue.main.async {
if cell.tag == indexPath.row {
cell.avatarImageView.image = UIImage(data: data)
}
}
}
task.resume()
}
//...
}
如果您仅在正确显示图像方面存在问题,我建议使用UIImageView
的highlightedImage
属性
UITableViewCell
具有。突出显示的
属性(当按下单元格时)。因此,如果单元格内部包含UIImageView
,则当您选择/高亮显示单元格时,UIImageView
将使用.highlightedImage
而不仅仅是.image
因此,作为问题的备份和修复,您可以另外提供/告知UIImageView
以显示头像,即使头像高亮显示。如果您只有正确的图像显示问题,我建议使用UIImageView
的highlightedImage
属性
UITableViewCell
具有。突出显示的
属性(当按下单元格时)。因此,如果单元格内部包含UIImageView
,则当您选择/高亮显示单元格时,UIImageView
将使用.highlightedImage
而不仅仅是.image
因此,作为问题的备份和修复,您还可以提供/告诉
UIImageView
以显示头像,即使头像高亮显示。感谢您提供的详细解释。设置Highlighte图像工作。感谢提供详细说明。设置高亮度图像工作。