我可以通过更改旧 ios 版本中的单元格框架来滑动 TableView 单元格的 contentView。但是,我无法在 Autolayout 中滑动它。在我的例子中,我创建了一个自定义的表格单元格,如下图所示:
我在滑动单元格之前删除了所有前导和顶部约束,但是仍然有一些约束阻止我滑动单元格,例如
"<NSAutoresizingMaskLayoutConstraint:0x8a39c60 h=--& v=--& UITableViewCellContentView:0x8a2f640.midX == + 160>",
"<NSAutoresizingMaskLayoutConstraint:0x8a39ca0 h=--& v=--& H:[UITableViewCellContentView:0x8a2f640(320)]>",
"<NSAutoresizingMaskLayoutConstraint:0x8a39ce0 h=--& v=--& UITableViewCellContentView:0x8a2f640.midY == + 21.5>",
"<NSAutoresizingMaskLayoutConstraint:0x8a39d20 h=--& v=--& V:[UITableViewCellContentView:0x8a2f640(43)]>"
但是,如果我使用
[self setTranslatesAutoresizingMaskIntoConstraints:NO];
在我的自定义单元格中,有一个问题:
*** Assertion failure in -[UITableView layoutSublayersOfLayer:], /SourceCache/UIKit_Sim/UIKit-2372/UIView.m:5776 2012-12-05 22:45:14.987 Slider[3773:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after executing -layoutSubviews. UITableView's implementation of -layoutSubviews needs to call super.'
我不知道怎么解决,请帮帮我。
最佳答案
我遇到了同样的问题。使用时出现错误
[aView setTranslatesAutoresizingMaskIntoConstraints:NO];
在单元格 contentView 上。表格 View 单元格似乎不支持此设置。
要解决这个问题,请将所有内容嵌入容器 View 并将其添加为表格 View 单元格的 subview 。
查看此答案 "Auto Layout still required after executing -layoutSubviews" with UITableViewCell subclass
关于ios - 如何在 Autolayout 中滑动 tableview 单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13725957/