问题描述
我面对我的UITableView一个非常奇怪的问题。
我有我想要显示的新闻源样表视图一些不同的细胞。
I'm facing a really weird problem on my UITableView.I have some different cells that I want to display on a newsfeed-like table view.
和我有回用后的单元格的问题。
该单元包含两个图像,两个标签和共享视图/像/注释按钮。
我要去尝试绘制它,但我不知道这会是pretty:
And I have a problem with a cell after reuse.The cell contains two images, two labels and a view with the share/like/comment buttons.I'm gonna try to draw it, but I'm not sure it's gonna be pretty :
-------------------------------------------------
| | __ ____________________________ |
| | |_2| | | |
| | | 3 | |
| | | | |
| 1 | |____________________________| |
| | |
| |_______________________________________|
| | |
| | 4 |
|_______|_______________________________________|
| |
| 5 |
|_______________________________________________|
1 : objectImage
2 : subjectImage
3 : titleLabel
4 : commentLabel
5 : actionsView
和我的约束是:
"H:|-0-[objectImage(60)]-7-[subjectImage(30)]-7-[titleLabel]-7-|"
"H:|-0-[objectImage(60)]-0-[commentLabel]-0-|"
"H:|-0-[actionsView]-0-|"
"V:|-0-[objectImage(>=35)]-0-[actionsView(44)]-0-|"
"V:|-7-[subjectImage(30)]"
"V:|-7-[titleLabel(>=46)]-7-[commentLabel(>=35)]-0-[actionsView(44)]-0-|"
和每一个单元格绘制的时候,我改变了约束:
And every time the cell is drawn, I change this constraint:
"V:[commentLabel(%0.2f)]"
细胞完全显示的第一次。
The cells display perfectly the first time.
不过,我的问题是,在一个点,一些回用后(我不能每次都重现)应用程序崩溃,因为的约束问题。
这里是个例外:
But, the problem I have is that at a point, after some reuse (I can't reproduce it every time) the app crashes because of a constraint problem.Here is the exception:
"<NSLayoutConstraint:0x205a75b0 V:[UILabel:0x1ef31430(105)]>",
"<NSLayoutConstraint:0x1ef34440 V:[UILabel:0x1ef31430]-(0)-[UIView:0x1ef2fe50]>",
"<NSLayoutConstraint:0x1ef34380 V:[UILabel:0x1ef31250]-(7)-[UILabel:0x1ef31430]>",
"<NSLayoutConstraint:0x1ef33900 V:|-(7)-[UILabel:0x1ef31250] (Names: '|':UITableViewCellContentView:0x1ef2bf50 )>",
"<NSLayoutConstraint:0x1ef34340 V:[UILabel:0x1ef31250(>=46)]>",
"<NSLayoutConstraint:0x1ef33210 V:[UIView:0x1ef2fe50]-(0)-| (Names: '|':UITableViewCellContentView:0x1ef2bf50 )>",
"<NSLayoutConstraint:0x1ef331d0 V:[UIView:0x1ef2fe50(44)]>",
"<NSAutoresizingMaskLayoutConstraint:0x1ef36f90 h=--& v=--& V:[UITableViewCellContentView:0x1ef2bf50(147)]>"
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x1ef34380 V:[UILabel:0x1ef31250]-(7)-[UILabel:0x1ef31430]>
问题是,约束[UITableViewCellContentView:0x1ef2bf50(147)是不正确的。
The problem is that the constraint [UITableViewCellContentView:0x1ef2bf50(147)] is not right.
什么是奇怪的是,heightForRowAtIndexPath:返回正确的值是217
What is weird is that the heightForRowAtIndexPath: returns the correct value which is 217.
和我不明白的是,的UITableViewCell的高度是正确的!
And what I don't understand is that the height of the UITableViewCell is correct!
(lldb) po 0x1ef2bf50
$0 = 519225168 <UITableViewCellContentView: 0x1ef2bf50; frame = (0 0; 320 147); gestureRecognizers = <NSArray: 0x1ef30a20>; layer = <CALayer: 0x1ef2a3d0>>
(lldb) po [0x1ef2bf50 superview]
$1 = 0x1ef30e40 <NewsSubjectCommentCell: 0x1ef30e40; baseClass = UITableViewCell; frame = (0 1055; 320 217); hidden = YES; autoresize = W; layer = <CALayer: 0x1ef25e10>>
所以,我不明白是怎么回事可能UITableViewCellContentView的高度限制是147.这是同类型的另一单元的高度,但应改为209,对吧?
So I don't understand how is it possible that the height constraint of UITableViewCellContentView is 147. It is the height of another cell of the same type, but it should be changed to 209, right?
所以,如果你有这种情况发生(也许我做错了什么)任何见解,我会很高兴。
So, if you have any insight on how this can happen (maybe I did something wrong), I'd be glad.
谢谢,
推荐答案
我找到了答案在这里:Auto在iOS7中的UITableViewCell 布局约束问题
I found the answer here : Auto layout constraints issue on iOS7 in UITableViewCell
我们只需要设置为内容查看UIViewAutoresizingFlexibleHeight的AutoresizingMask |!UIViewAutoresizingFlexibleWidth和...问题解决了
We just have to set the AutoresizingMask of the contentView to UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth and ... problem solved!
这篇关于这怎么可能,UITableViewCellContentView高度不同于heightForRowAtIndexPath:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!