繁体   English   中英

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

[英]Resize table cell after image downloaded

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

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

图像设置到图像视图后,单元格未正确调整大小 在此输入图像描述

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

在此输入图像描述

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
}

您可以为表格单元格使用自动尺寸。

tableView.rowHeight = UITableViewAutomaticDimension

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM