ios - UITableView 动态单元格高度冲突 - 高度不依赖于标签

标签 ios uitableview uitableviewautomaticdimension

因此,我的 TableView 显示图像。每个单元格基本上都是一个图像,填充了整个 contentView 的单元格。由于图像具有不同的纵横比,我需要我的单元格根据表格 View 的宽度和图像的纵横比调整它们的高度。我关注了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)]>

ImageView 具有以下约束,并将单元格 contentView 作为 super View 。

Constraints

在 TableView Controller 类中,我正在使用

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)]>" 但是怎么做呢?另外,有没有人知道一些关于如何正确创建具有动态内容的表格 View 的文档/教程,这些动态内容不仅涵盖了单元格内的一堆标签吗?我的代码工作就好了,如果 ImageView 被标签取代......

最佳答案

您的实现是正确的,不要更改您的代码或任何约束中的任何内容。删除警告很容易,只需选择高度约束并将其优先级从 1000 降低到 999,它将修复您的警告。如果它仍然出现,让我知道。

关于ios - UITableView 动态单元格高度冲突 - 高度不依赖于标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37859594/

相关文章:

ios - 我可以让我的 UIView 的框架匹配它的曾祖 parent 吗?

ios - 升级到 iOS9 后,我在 iPhone 6、6s、6p 和 6sp 上的应用程序被拉伸(stretch)

ios - 此类不符合键的键值编码

下载图像后 iOS 更新表头高度(约束未更新)

ios - UITableViewCell 内容在滚动时合并

ios - 错误 : UITableView jump to top with UITableViewAutomaticDimension

ios - UITableViewAutomaticDimension 未按预期工作。 swift

ios - NSString字符我[16]

ios - 如何在 UITableView 中创建刷新按钮

具有异步获取的动态大小图像的 iOS UITableViewCell