【发布时间】:2020-07-29 14:17:52
【问题描述】:
如果条件不存在,我需要隐藏一个单元格。只是设置 cell.isHidden 不起作用,所以我能找到的唯一其他选项是将 hightForRowAt 设置为 0。这在视觉上效果很好,但会触发控制台警告:如何隐藏单元格而不一直触发此警告?
[LayoutConstraints] 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:0x282346080 UIView:0x104dbdb40.centerY == UITableViewCellContentView:0x104d22140.centerY (active)>",
"<NSLayoutConstraint:0x2823460d0 V:|-(11)-[UIView:0x104dbdb40] (active, names: '|':UITableViewCellContentView:0x104d22140 )>",
"<NSLayoutConstraint:0x282370320 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x104d22140.height == 0 (active)>"
)
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
var rowHeight: CGFloat = 200
switch indexPath.section {
case 0:
switch indexPath.row {
case 0:
rowHeight = 125
case 1:
rowHeight = 97
case 2:
if let workoutLocations = Metadata.workoutLocations {
if workoutLocations.count > 0 {
// rowHeight = 200
rowHeight = 220
} else {
return 0
}
} else { return 0}
case 3:
rowHeight = 446
case 4:
rowHeight = 302
case 5:
rowHeight = 302
case 6:
rowHeight = 162
case 7:
rowHeight = 192
default: ()
}
default: ()
}
return rowHeight
}
【问题讨论】:
-
看起来你有一个等于 11 的垂直间距约束。使
-
@PhillipMills 不,我试过了,但几乎任何约束都会触发警告,也许如果我将它们连接到 IBOutlet 并一一删除它们? ????
-
@GarySabo - 您是否在 Storyboard 中设计静态单元格?或者,您是否设计了要重复使用的原型单元?
-
@DonMag 这些是静态单元格
-
@omerfarukozturk 我认为这不适用于静态单元格? ??? cellForRowAt 不会覆盖我在情节提要中的单元格吗?
标签: ios swift xcode uitableview