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
}
自動レイアウトを使用しましたか? – TangZijian
ダウンロードした画像を設定した後、 'tablecell'で' layoutIfNeeded() 'を呼び出せますか? – san
次のリンクをたどる http://stackoverflow.com/questions/31805341/swift-custom-uitableviewcell-with-uiimageview-need-to -resize-cell-to-image-hei – ashwini