简体   繁体   中英

Resize table cell after image downloaded

I am using SDWebImage library to download image and load into image view inside a table cell.

I want to resize the table cell after the image is downloaded. Please advice. Many thanks.

Cell is not resize correctly after image set into image view 在此输入图像描述

Cell resize correctly after dequeue and load again

在此输入图像描述

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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