gpt4 book ai didi

uitableview - 自定义 UITableViewCell 垂直布局约束导致错误

转载 作者:行者123 更新时间:2023-12-04 21:40:41 25 4
gpt4 key购买 nike

当我在 iPhone 上运行我的应用程序时,出现以下错误。当我在模拟器中运行它时,我没有。如果我拿 -12-|离开然后单元格的高度折叠到大约 30 像素。并且用户界面中断了。
有人可以帮助我并告诉我为什么吗?

谢谢

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. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x170285ff0 V:|-(12)-[UIImageView:0x1741ec200] (Names: '|':UITableViewCellContentView:0x17419c7d0 )>",
"<NSLayoutConstraint:0x170286040 V:[UIImageView:0x1741ec200(200)]>",
"<NSLayoutConstraint:0x170286090 V:[UIImageView:0x1741ec200]-(12)-| (Names: '|':UITableViewCellContentView:0x17419c7d0 )>",
"<NSLayoutConstraint:0x174881f40 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x17419c7d0(224)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x170286090 V:[UIImageView:0x1741ec200]-(12)-| (Names: '|':UITableViewCellContentView:0x17419c7d0 )>
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.
Warning once only: Detected a case where constraints ambiguously suggest a height of zero for a tableview cell's content view. We're considering the collapse unintentional and using standard height instead.
Unable to simultaneously satisfy constraints.

在自定义 UITableViewCell我定义了布局约束如下:
_imgView.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-15-[imageView]-15-|" options:0 metrics:nil views:@{ @"imageView": _imgView }]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-12-[imageView(200)]-12-|" options:0 metrics:metrics views:@{ @"imageView" : _imgView }]];

- - 编辑 - -

回复 contentView.bounds建议:
在我的 UITableViewController我执行以下操作:
_tableView.rowHeight = UITableViewAutomaticDimension;
_tableView.estimatedRowHeight = 30.0f;

所以零高度应该不是问题。

最佳答案

单元格的初始高度可能小于垂直约束。这会产生初始高度冲突,直到 contentView 的框架发生变化。
您可以使用以下方法之一解决此问题:

  • 增加 Storyboard中单元格的高度以最初适合内容。
  • 将单元格的 contentView 的边界更改为更大的尺寸:self.contentView.bounds = CGRectMake(0, 0, 99999, 99999);

  • 您可以在 this auto layout question 的答案中找到更多详细信息。 .
    更新 :
    “无法同时满足约束”冲突发生在试图将单元格高度设置为 225 点的 imageView 约束和试图将单元格高度设置为 224 点的固定高度之间。
    您的 imageView 垂直约束使用 224 (12 + 200 + 12) 点。 tableView 分隔符使用 1 点。因此,要满足所有约束,单元格高度需要为 225 点。

    关于uitableview - 自定义 UITableViewCell 垂直布局约束导致错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27400714/

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