簡體   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