我正在尝试检索图像,然后在单元格中显示它们。每个图像的宽度应该相同,但高度可以变化 - 因此,我需要自动调整单元格大小。
我这样做是为了检索图像并进行缩放:
cell.thumbnail.sd_setImageWithURL(NSURL(string: imageURL), placeholderImage: blankImage)
cell.thumbnail.contentMode = UIViewContentMode.ScaleToFill
这是为了让单元格大小动态变化:
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension;
}
但我无法让它发挥作用!
问题是:
1)图像看起来超高度伸展
2)我必须滚过图像然后回到它才能看到比率变化
3)滚动是超级毛刺(不是因为图像加载)
4)我有一个segue,从细胞到另一个视图控制器。一旦我点击单元格,整个表格就会出现故障。当我回到它时,所有图像都以完全不同的方式调整大小。
我正确设置了约束,所以我知道这不是问题。
答案 0 :(得分:0)
也可以尝试调用它:
func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
答案 1 :(得分:0)
初始化表视图时,请执行以下操作:
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 500 //Put just any approximate average height for cell. This will just be used to show scroll bar offset.
删除方法:
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension;
}