首页 > 解决方案 > 如何在后台加载图像时继续用文本填充表格视图单元格

问题描述

我从存储在数组中的 api 读取两个属性(名称和图像)。我知道如何在表格中显示它们,但我不知道如何在显示名称后制作表格移动到下一行而不等待加载图像。我想在后台加载图像并在完成后显示它。

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("customcell", forIndexPath: indexPath) as! UITableViewCell
//when i get text move on next cell not waiting for image to be loaded
        cell.textLabel?.text = myarray[indexPath.item].name
//make this image loading in background
         cell.imageView?.image = myarray[indexPath.item].image
        return cell
    }

这是图片: 在此处输入图像描述

标签: iosswiftuitableviewuiimage

解决方案


推荐阅读