2016-06-16 48 views
1

因此,我的表格视图显示图像。每个细胞基本上都是填充细胞整个contentView的图像。由于图像具有不同的宽高比,因此我需要我的单元格根据图像宽度和宽高比来调整高度。我跟着this Ray Wenderlich教程,但现在得到一个约束冲突。图像通过改变imageView的高度约束来调整大小,例如, myImageViewHeight.constant = tableView.frame.width/aspectRatioUITableView动态单元高度冲突 - 高度不取决于标签

2016-06-16 13:56:25.823 MyApp[92709:5649464] Unable to simultaneously satisfy constraints. 
Probably at least one of the constraints in the following list is one you don't want. 
Try this: 
    (1) look at each constraint and try to figure out which you don't expect; 
    (2) find the code that added the unwanted constraint or constraints and fix it. 
(
"<NSLayoutConstraint:0x7fbcdaf5c190 V:[UIImageView:0x7fbcdaf5c300(303)]>", 
"<NSLayoutConstraint:0x7fbcdaf5b460 V:|-(0)-[UIImageView:0x7fbcdaf5c300] (Names: '|':UITableViewCellContentView:0x7fbcdaf52230)>", 
"<NSLayoutConstraint:0x7fbcdaf5b4b0 V:[UIImageView:0x7fbcdaf5c300]-(0)-| (Names: '|':UITableViewCellContentView:0x7fbcdaf52230)>", 
"<NSLayoutConstraint:0x7fbcdaf5e550 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7fbcdaf52230(100)]>" 
) 

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7fbcdaf5c190 V:[UIImageView:0x7fbcdaf5c300(303)]> 

的图像视图具有以下约束,并且具有细胞contentView如上海华。

Constraints

在表视图控制器类,我使用

self.tableView.estimatedRowHeight = 80 
self.tableView.rowHeight = UITableViewAutomaticDimension 

我也试过这 - 同样的结果。

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

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

我猜我必须摆脱'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7fbcdaf52230(100)]>"但如何?另外,是否有人知道如何正确创建表格视图与动态内容的一些文档/教程,不仅覆盖在单元格内有一堆标签?我的代码工程就好了,如果图像视图被替换为标签...

+0

删除您的imageview高度约束,并在检查后。你是设置顶部和底部约束,你没有设置高度相等的约束。 –

+0

@Bhadresh如果高度限制被删除,图片如何获得适当的高度? – Percolator

+0

你的图像修复高度,删除顶部和底部约束和设置中心约束。 –

回答

5

你的实现是正确的不要改变任何东西在你的代码或任何约束。撤消警告很容易,只需选择高度限制,并将其优先级从1000降低到999,它将修复您的警告。如果它仍然存在,请告诉我。

相关问题