2015-04-15 41 views
0

我试图检索图像,然后将它们显示在单元格中。每个图像的宽度应该相同,但高度可能会有所不同 - 因此,我需要单元格大小自动调整。无法获取单元格自动高度来工作

我这样做是为了获取图像和规模:

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)I必须滚动过去的图像,然后返回到它只是为了看看比率变化

3)滚动是非常糟糕的(这不是因为图像加载)

4)我有一个从细胞通向另一个视图控制器的segue。一旦我点击单元格,整个表格就会出现一秒钟的问题。当我回到它时,所有图像都以完全不同的方式调整大小。

我正确设置了约束,所以我知道这不是问题。

+0

在看了约束,但是我可以真的看不到它,你对imageVew有高度限制吗? –

回答

0

尝试调用此还有:

func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { 
    return UITableViewAutomaticDimension 
} 
+0

仍然是同样的问题 - 我必须单击单元格,然后返回到页面以查看一切刷新。当它发生时,高度全部拉长 –

+0

我建议重新检查一下你的约束以及你的图像是如何加载的。我已经使用estimatedHeight和heightForRow来获得自动细胞高度的工作。我已经在5-6个项目中使用过它,从来没有任何问题。 – Nick

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

试过了。仍然有同样的问题。这是我的[限制](http://s16.postimg.org/ffx57mr51/Screen_Shot_2015_04_14_at_10_35_34_PM.png)。我是否正确缩放图像? –

相关问题