gpt4 book ai didi

ios - 在 cellForRowAtIndexPath 中更改 NSLayoutConstraint 常量不断导致 "unable to satisfy constraints"错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:00:31 27 4
gpt4 key购买 nike

我的应用程序中有很多这样的单元格。有些 self 调整大小,有些则没有。

例如,假设我们有一个自定义的 UITableViewCell。 100 高度。在它的内容 View 中,我们拖动了 2 个 UIView。 UIViewTop 和 UIViewBottom。每个50高。 UIViewTop 我们放在内容 View 的顶部,并给它 Leading/Trailing/Top/Height 约束。 UIViewBottom 我们放在内容 View 的底部,并给它 Leading/Trailing/Bottom/Height 约束。我们还在 UIViewTop 和 UIViewBottom 之间提供 Vertical Spacing 约束。

现在,有时我们只想显示 UIViewTop,而其他时候我们希望显示 UIViewTop 和 UIViewBottom。所以我们将 UIViewBottomHeight Constraint 拖出作为 IBOutlet NSLayoutConstraint。

然后,在 cellForRowAtIndexPath 中...我们将此 IBOutlet 约束设置为 0 或 50,具体取决于我们是否要显示该部分。

如果我们有 self 调整大小的单元格,我们什么都不做。如果我们没有自动调整大小的单元格,则单元格的大小在 heightForRowAtIndexPath 中准确确定。

在这两种情况下我都会收到警告。在调试器中,它会在以下代码之后立即发生...

`cell.constraintUIViewBottomHeight.constant = __`

我希望能够更改约束常量,但不希望在控制台中收到 Unable to simultaneously satisfy constraints 警告。

最佳答案

我猜 constraintUIViewBottomHeight 约束的优先级是 Required/1000..我会通过将优先级降低到 999 或其他东西来消除警告来试一试..

关于ios - 在 cellForRowAtIndexPath 中更改 NSLayoutConstraint 常量不断导致 "unable to satisfy constraints"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31297894/

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