forkingdog / UITableView-FDTemplateLayoutCell

Template auto layout cell for automatically UITableViewCell height calculating
MIT License
9.94k stars 2.01k forks source link

10.3 自适应不行了 #289

Closed JWXIAN closed 7 years ago

JWXIAN commented 7 years ago

12a1e78d556d6d39734e42c90ac506cf

Er01c commented 7 years ago

@JWXIAN https://github.com/SnapKit/Masonry/issues/426

JWXIAN commented 7 years ago

这是自适应失效了?

KenmuHuang commented 7 years ago

+1,希望能自适应处理好 10.3 系统下使用 Masonry 约束的高度计算

apascual commented 7 years ago

Same problem here...

apascual commented 7 years ago

I found the problem...

It looks like for some UILabel, a preferredMaxLayoutWidth is configured, mainly when they are created using the Storyboard/NIB file. And the problem is that the value available at the time that the Cell is created is the one it had on the Storyboard...

Setting all the label's preferredMaxLayoutWidth to 0 fixed the problem for me, i.e.:

self.labelnsideCell.preferredMaxLayoutWidth = 0;

apascual commented 7 years ago

Or even better:

self.labelnsideCell.preferredMaxLayoutWidth = self.frame.size.width;

yudun1989 commented 7 years ago

https://github.com/yudun1989/UITableView-FDTemplateLayoutCell/commit/b300c2eaad4dbfd6524919f38aad3f130e776649

暂时给contentView加上了上下左右的约束

10.3在调用systemLayoutSizeFittingSize的时候会多添加几条width和height的约束,导致约束冲突

tyrad commented 7 years ago

我现在的解决办法是在awakeFromNib中计算出label的实际宽度,并赋值给label.preferredMaxLayoutWidth(我的cell是用xib写的)

faimin commented 7 years ago

归根结底还是得设置多行labelpreferredMaxLayoutWidth属性,我的设置好之后就正常了

HomerLi commented 7 years ago

问题: 项目中使用 XIB 布局, 单个 cell 对应 单个view, 第一次打开带 多行 label 的 cell 时, 布局正常. 再打开其他的带多行 label的 cell 时, 自动布局失效,即行高计算错误. 解决方法: 目前 设置 label 的 preferredMaxLayoutWidth 在我的项目中不起作用 我的解决方法是 在 awakeFromNib 中填加如下代码:

[self layoutIfNeeded];
self.noteLabel.lineBreakMode = NSLineBreakByWordWrapping;(此行只在有多行 label 的 cell 视图中添加)

lineBreakMode 枚举中, 选择前三个任意一个, 布局正常. PS: 当打开一个行高计算错误的 cell 后, 之后打开的 cell 继续计算错误. 所以需要将所有用到缓存行高的 cell (包括没有多行 label 的 cell) 全部修改,即 不会再出现计算错误的情况下, cell 显示正常.

13hoop commented 7 years ago

10.3 systemLayoutSizeFittingSize自动有width和height约束 导致约束冲突

使用preferredMaxLayoutWidth设置时注意

LynahZ commented 7 years ago

纯代码项目中,使用Masonry和FD自适应cell高度,也出现一样的问题,这种情况应该怎么解决呢,每个cell都对应设置一下preferredMaxLayoutWidth

FreshAlpha commented 7 years ago

重新约束contentView self.contentView.mas_remakeConstraints { (m: MASConstraintMaker!) in m.edges.equalTo()(self) } 并且在cell的xib中更改cell的width为较大值。 测试有效。

taogeyijiu commented 7 years ago

楼主看到你的帖子,我赶紧看了一下我的界面,iOS10.3没有发现问题呀,好多人都说设置preferredMaxLayoutWidth, 我也没设置过呀,不知道你的问题出在哪里???我也是用的纯代码+ Masonry

yudun1989 commented 7 years ago

@taogeyijiu 用nib布局会出问题

xiongoahc commented 7 years ago

+1

xiongoahc commented 7 years ago

设置多行label的preferredMaxLayoutWidth就好啦

afantree commented 7 years ago

结论: 多行label的preferredMaxLayoutWidth的问题

zidonJ commented 6 years ago

I resolve this use a estimatedRowHeight and set a value not zero. It is very helpful.

pusswzy commented 5 years ago

I resolve this use a estimatedRowHeight and set a value not zero. It is very helpful.

thank you