【发布时间】:2017-07-02 12:25:37
【问题描述】:
我看了3天动态表格单元格和自动布局相关的文章,至今没用。
下面是我想要的表格单元格。这里的主要问题是用于发布文本和 UIImages 的 UILabel。
这是 UI 元素的层次结构。
- Content View
+ ...
+ UILabel for text - dynamic height
+ UIView - image view container
* UIImageView
* UIImageView
* ....
标签的换行模式换行文本和行设置为 0。 标签和容器视图具有顶部、底部、前导和尾随的约束。 ImageViews 在运行时添加,并具有顶部、前导、尾随、底部和高度约束的约束。 第一个图像视图对容器视图具有顶部约束,最后一个图像视图对容器视图具有底部约束,其他图像视图对上部图像视图具有顶部约束。
第一次加载表格时(单元格具有不同的图像计数),它看起来很好,但是当我向上和向下滚动时,某些单元格中的约束被破坏并且图像在单元格内重叠。
这是错误输出:
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:0x17428aaf0 V:|-(0)-[UIImageView:0x14be77ed0] (active, names: '|':UIView:0x14be75b20 )>",
"<NSLayoutConstraint:0x17428a6e0 UIImageView:0x14be77ed0.height == 160 (active)>",
"<NSLayoutConstraint:0x17428acd0 UIImageView:0x14be77ed0.bottom == UIView:0x14be75b20.bottom (active)>",
"<NSLayoutConstraint:0x174289650 V:|-(0)-[UIImageView:0x14be43ce0] (active, names: '|':UIView:0x14be75b20 )>",
"<NSLayoutConstraint:0x17428bb80 UIImageView:0x14be43ce0.height == 160 (active)>",
"<NSLayoutConstraint:0x17428be50 V:[UIImageView:0x14be43ce0]-(10)-[UIImageView:0x14be74b10] (active)>",
"<NSLayoutConstraint:0x17428bfe0 UIImageView:0x14be74b10.height == 160 (active)>",
"<NSLayoutConstraint:0x17428c080 UIImageView:0x14be74b10.bottom == UIView:0x14be75b20.bottom (active)>"
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x17428be50 V:[UIImageView:0x14be43ce0]-(10)-[UIImageView:0x14be74b10] (active)>
请帮我解决这个问题。谢谢。
【问题讨论】:
-
您能否显示更多代码或情节提要或单元格?
-
一个单元格最多可以显示多少张图片?
-
@HimanshuMoradiya,没有限制。用户可以附加他们想要的图片。
标签: ios objective-c iphone uitableview autolayout