blo*_*ork 9 uitableview ios autolayout ios8
我有一个tableview单元格,其视图从一个笔尖加载,其子视图使用AutoLayout进行约束.我正在使用iOS 8的自调整大小功能.在第一次显示时,单元格如下所示:

绿色视图与蓝色和灰色视图之间的边距比我预期的要大.如果我向下滚动视图以便创建更多单元格,或者如果我在tableview上调用reloadData,那么我会得到正确的结果:

就好像单元格子视图的大小不正确,直到第二个布局通过.我怎么能绕过这个?我已经看到了一些职位,建议设置setPreferredMaxLayoutWidth的layoutSubviews,就像这样:
-(void)layoutSubviews
{
[super layoutSubviews];
[self.redLabel setPreferredMaxLayoutWidth:[self.titleLabel bounds].size.width];
[self.greenLabel setPreferredMaxLayoutWidth:[self.extendedLabel bounds].size.width];
[self.blueLabel setPreferredMaxLayoutWidth:[self.dateLabel bounds].size.width];
[self.grayLabel setPreferredMaxLayoutWidth:[self.tagsLabel bounds].size.width];
[super layoutSubviews];
}
Run Code Online (Sandbox Code Playgroud)
......但似乎没有效果.
我的约束似乎没有任何歧义,但由于它们是在.nib中设置的,我不知道如何在这里发布它们.
所以我将蓝色/灰色视图的顶部空间设置为> =绿色视图的底部,+ 3.这实际上是我得到的,因为空间更大.
但是,如果我将关系设置为==,我会得到一个不同的视觉错误,其中红色标签的大小不正确,因为它包含的文本数量:

不确定我是否应该开始一个新问题,但这是同样的问题.
在编辑1中仍然存在布局的反复出现的问题.除了视觉问题,当我的tableview中的单个单元格发生变化时,它会导致可怕的效果.整个列表似乎会崩溃并重新加载.此外,我记录以下自动布局错误:
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. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x797c5bc0 UITableViewCellContentView:0x7970adc0.(null) == UILabel:0x79707cf0.trailing + 6>",
"<NSLayoutConstraint:0x7977b560 UILabel:0x79707cf0.leading == UITableViewCellContentView:0x7970adc0.(null) + 6>",
"<NSLayoutConstraint:0x7970a700 UITableViewCellContentView:0x7970adc0.width ==>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x797c5bc0 UITableViewCellContentView:0x7970adc0.(null) == UILabel:0x79707cf0.trailing + 6>
Run Code Online (Sandbox Code Playgroud)
UILabel所指的是较长的绿色标签.似乎无法将前导约束和尾随约束与细胞具有的任何宽度相协调,就好像细胞总体上小于12个点一样.然而,记录宽度似乎总是导致320.
难道不是layout的问题,而是cell高度计算的问题?我会仔细检查您的estimatedHeightForRowAtIndexPath 或heightForRowAtIndexPath。
| 归档时间: |
|
| 查看次数: |
3918 次 |
| 最近记录: |