我第一次切换到延迟时,我有一个带有自定义单元格的tableView,在查找问题后,我发现显示照片是寻找问题的原因,但没有任何帮助。我试图在主队列中进行过渡
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as? TVCellMenu else { return UITableViewCell()}
let data = category[indexPath.row]
cell.title.text = data.name
//image is reason
let image = UIImage(named: data.image_name ?? "", in: Bundle.main, compatibleWith: nil)
cell.ImageView.image = image
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let storyBoard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyBoard.instantiateViewController(withIdentifier: "menu") as! VCMenu
vc.isCategory = false
vc.subCategory = self.category[indexPath.row].subCategory
vc.position = self.category[indexPath.row].position
navigationController?.pushViewController(vc, animated: true)
}
答案 0 :(得分:0)
当加载图像的速度变慢时,您应该考虑异步加载图像。
例如:
向TVCellMenu添加功能:
func loadImage(imageName: String) {
DispatchQueue.main.async {
let image = UIImage(named: imageName ?? "", in: Bundle.main, compatibleWith: nil)
self.ImageView.image = image
}
}
然后(而不是直接设置图像)只需调用cellForRowAt中的函数:
cell.loadImage(imageName: data.image_name ?? "");
return cell