[英]how to reuse tableviewCell with autoLayout in swift?
I have a tableview cell with an imageview and a button inside it. 我有一个tableview单元格,其中有一个imageview和一个按钮。 I add constraints for imageview and button.
我为imageview和button添加了约束。 The tableview appears and the cell is displayed correctly.
出现表格视图,并且单元格正确显示。 But when reuse the cell, I scroll down the tableView and scroll back up, cells are displayed wrong?
但是,当重用单元格时,我向下滚动tableView并向上滚动回来,单元格显示错误吗?
When I reuse the cell I add new constraints, there are conflicts with earlier constraints,I try to delete earlier constraints before adding new constraints but it does not work. 当我重用单元格时,我添加了新的约束,但与先前的约束存在冲突,因此我尝试在添加新的约束之前先删除较早的约束,但这是行不通的。 Here is the project link:
这是项目链接:
https://github.com/chengyanan/chat https://github.com/chengyanan/chat
console throw warnings in case of autolayout errors: 在自动布局错误的情况下,控制台抛出警告:
2015-12-10 16:34:30.299 Chat[5488:133086] 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:0x7cc5b120 H:[UIImageView:0x7c94daa0(30)]>",
"<NSLayoutConstraint:0x7cc5a640 H:|-(8)-[UIImageView:0x7c94daa0](LTR) (Names: '|':UITableViewCellContentView:0x7c96bdb0 )>",
"<NSLayoutConstraint:0x7ccab9e0 UIImageView:0x7c94daa0.right == UITableViewCellContentView:0x7c96bdb0.right - 8>",
"<NSLayoutConstraint:0x7cc71dc0 'UIView-Encapsulated-Layout-Width' H:[UITableViewCellContentView:0x7c96bdb0(320)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7ccab9e0 UIImageView:0x7c94daa0.right == UITableViewCellContentView:0x7c96bdb0.right - 8>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2015-12-10 16:34:30.300 Chat[5488:133086] 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:0x7cc5b120 H:[UIImageView:0x7c94daa0(30)]>",
"<NSLayoutConstraint:0x7cc59d40 H:[UIImageView:0x7c94daa0]-(3)-[UIButton:0x7c95b8b0'Trgghhh hhhhhhhhhhhbbbbbv...'](LTR)>",
"<NSLayoutConstraint:0x7cc78640 H:[UIButton:0x7c95b8b0'Trgghhh hhhhhhhhhhhbbbbbv...'(255)]>",
"<NSLayoutConstraint:0x7ccc99f0 UIButton:0x7c95b8b0'Trgghhh hhhhhhhhhhhbbbbbv...'.right == UIImageView:0x7c94daa0.left - 3>"
)
Do you need to always remove and add new constraints? 您是否需要始终删除并添加新约束? could you perhaps modify the current constraints in a UITableViewCell method during cellForRowAtIndexPath and it will layout correctly.
您是否可以在cellForRowAtIndexPath期间修改UITableViewCell方法中的当前约束,它将正确布局。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.