【发布时间】:2018-05-11 04:48:50
【问题描述】:
我有一个与此处发布的非常相似的问题 (Dynamic UIImageView Size Within UITableView),我正在尝试从 Firebase 动态检索图像,并使生成的 tableview 调整到图像的高度,给定屏幕上的固定宽度纵横比。我读过的所有文章都说基于 cellforRowAt 进行单元格计算,但我的实际图像在 TableViewCell 内。有人可以帮忙吗?
表格视图控制器:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "FeedTableViewCell", for: indexPath) as! FeedTableViewCell
cell.configureCell(post: postArray[indexPath.row])
return cell
}
TableViewCell:
func configureCell(post: Post){
self.postImage.sd_setImage(with: URL(string: post.postImageURL),
placeholderImage: UIImage(named: "default"))
}
【问题讨论】:
-
使用 Disptach.main.asyn{cell. postImage.kf.setImage(with: URL) { _, _, _, _ in cell.layoutIfNeeded() } }
标签: ios swift tableview swift4