所以,我的表视图显示图像 . 每个单元格基本上都是填满整个单元格的图像 contentView
. 由于图像具有不同的宽高比,我需要我的单元格根据表格视图宽度和图像的纵横比调整其高度 . 我遵循了this Ray Wenderlich教程但现在遇到了约束冲突 . 通过改变 imageView
的高度约束来调整图像大小,例如 myImageViewHeight.constant = tableView.frame.width / aspectRatio
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
为superview .
在表视图控制器类中,我正在使用
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)]>"
但是怎么样?另外,是否有人知道如何正确创建具有动态内容的表视图的文档/教程 not only 涵盖单元格内有一堆标签?如果图像视图被标签替换,我的代码 works 就好了......
1 回答
您的实现是正确的,不要更改代码中的任何内容或任何约束 . 移动警告很容易只需选择高度约束并将其优先级从1000降低到999它将修复您的警告 . 如果它仍然存在,请告诉我 .