【发布时间】:2018-08-14 09:30:40
【问题描述】:
我正在使用 Swift 4,由于这些在线图像的高度,我想获取在线图像并调整表格视图单元格高度和表格视图高度。我正在使用SDWebImage 显示在线图片,这是代码:
var images = ["http://styliee.com/images/products/6d9vH1Kk2r.jpeg","http://styliee.com/images/products/6d9vH1Kk2r.jpeg"]
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "ProductImageTableViewCell", for: indexPath) as! ProductImageTableViewCell
let imageUrl = URLs.productImageUrl + self.product.images[indexPath.row].name
cell.adImage.sd_setImage(with: URL(string: imageUrl))
cell.layoutIfNeeded()
cell.layoutSubviews()
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
但它不能正常工作, 有什么帮助吗?
【问题讨论】:
-
如果您从后端获取图像,则从后端获取图像的比例并根据比例调整表格视图单元格的高度
-
请展示您的 imageView 的约束