2016-03-23 11 views
1

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 
} 
+0

自動レイアウトを使用しましたか? – TangZijian

+0

ダウンロードした画像を設定した後、 'tablecell'で' layoutIfNeeded() 'を呼び出せますか? – san

+0

次のリンクをたどる http://stackoverflow.com/questions/31805341/swift-custom-uitableviewcell-with-uiimageview-need-to -resize-cell-to-image-hei – ashwini

答えて

0

あなたはテーブルビューセルの自動ディメンションを使用することができ読み込む正しくサイズを変更されていません。

tableView.rowHeight = UITableViewAutomaticDimension 
+1

はい私はrowHeightをUITableViewAutomaticDimensionとして設定しました。プレースホルダ画像が設定されていて、画像をダウンロードする必要がある場合は機能しません – PrimaryChicken

+0

あなたは別途画像をダウンロードしていますか? –

+0

イメージビューをアスペクトの塗りつぶしに変更できますか? –

関連する問題