gpt4 book ai didi

ios - UITableViewCellContentView 高度怎么可能不同于 heightForRowAtIndexPath :

转载 作者:IT王子 更新时间:2023-10-29 08:08:46 26 4
gpt4 key购买 nike

我的 UITableView 遇到了一个非常奇怪的问题。我有一些不同的单元格,我想在类似新闻源的表格 View 中显示。

重复使用后,我的电池出现问题。该单元格包含两个图像、两个标签和一个带有分享/喜欢/评论按钮的 View 。我会尝试画它,但我不确定它会很漂亮:

-------------------------------------------------
| | __ ____________________________ |
| | |_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-|"

每次绘制单元格时,我都会更改此约束:

"V:[commentLabel(%0.2f)]"

单元格第一次显示完美。

但是,我遇到的问题是,在某些重用(我不能每次都重现)之后,应用程序由于约束问题而崩溃。这是异常(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)] 不对。

奇怪的是 heightForRowAtIndexPath: 返回正确的值 217。

我不明白的是 UITableViewCell 的高度是正确的!

(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,是另一个同类型cell的高度,但是应该改成209吧?

因此,如果您对这是如何发生的有任何见解(也许我做错了什么),我会很高兴。

谢谢,

最佳答案

我在这里找到了答案:Auto layout constraints issue on iOS7 in UITableViewCell

我们只需要将 contentView 的 AutoresizingMask 设置为 UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth 并且...问题解决了!

关于ios - UITableViewCellContentView 高度怎么可能不同于 heightForRowAtIndexPath :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16039845/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com