Swift 具有自定义单元格和延迟的tableView

Swift 具有自定义单元格和延迟的tableView,swift,image,uitableview,tableview,Swift,Image,Uitableview,Tableview,我有一个带有自定义单元格的tableView,当我第一次切换到有延迟时,在搜索问题后,我发现显示照片是我查找问题的原因,但没有任何帮助。我试图在主队列中进行转换 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { guard let cell = tableView.dequeueReusableCell(withIdentifie

我有一个带有自定义单元格的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)

}

加载图像时要慢,应考虑加载异步。 例如:

向TVCell功能表添加功能:

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

加载图像时要慢,应考虑加载异步。 例如:

向TVCell功能表添加功能:

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

主队列中的哪个转换?在didSelectRowAt中?@Sh_Khan在didSelectRowAt中是主队列中的哪个转换?在didSelectRowAt中?@Sh_Khan在didSelectRowAt中是的