下载映像后调整表格单元格大小

时间:2016-03-23 11:53:17

标签: ios uitableview sdwebimage

我正在使用SDWebImage库下载图像并加载到表格单元格内的图像视图中。

我想在下载图像后调整表格单元格的大小。请指教。非常感谢。

图像设置到图像视图后,单元格未正确调整大小 enter image description here

出列并再次加载后,单元格正确调整大小

enter image description here

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cell = tableView.dequeueReusableCellWithIdentifier(GagListTableViewCell.cellId, forIndexPath: indexPath) as! GagListTableViewCell
    cell.layoutMargins = UIEdgeInsetsZero
    let gagDataCommand = gagDataSource[indexPath.row]

    if let caption = gagDataCommand.caption {
        cell.captionLabel.text = caption
    }

    if let imageUrlStr = gagDataCommand.images?.normal {
        if let imageUrl = NSURL(string: imageUrlStr) {                
            cell.gagImage.sd_setImageWithURL(imageUrl, placeholderImage: UIImage(named: AppConstants.imagePlaceHolderName), completed: { (image, error, cacheType, url) in
                 //guess I need to redraw the layout here
            })
        } else {
            //fail to get image url, set placeholder image to the cell instead
            cell.gagImage.image = UIImage(named: AppConstants.imagePlaceHolderName)
        }
    }

    return cell
}

1 个答案:

答案 0 :(得分:0)

您可以为tableview单元格使用自动维度。

var interval = setInterval(function () 
{
    // call generation again for each generation, passing in the previous generations best offspring
    best_offspring = generation(best_offspring, characters, amount_offspring, mutation_rate, target_text);
    document.getElementById("output_text").value = best_offspring;
    document.getElementById("generations").value = generations;
    if (score_met || stop.called) 
    {
        clearInterval(interval);
    }
}, delay);

if (stop.called)
{
    clearInterval(interval);
    return;
}

// so that we know that the program has been run atleast once
start = true;
}