【问题标题】:iOS: Unable to simultaneously satisfy constraints when in segueiOS:在 segue 中无法同时满足约束
【发布时间】:2014-10-14 08:11:33
【问题描述】:

我正在尝试从 tableview 到 UIViewController 进行 segue,但我遇到了一个奇怪的错误。即使目标视图完全为空,只是添加到情节提要中,也会发生错误。我的想法是发送视图的某些元素触发了错误,但我很困惑为什么这仅在退出该 TableViewController 时显示,而不是在最初加载它时显示。

这是错误的堆栈跟踪:

Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2014-10-14 00:52:23.472 Phood[54950:70b] 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:0x9d56270 H:[PHStarsView:0x9d9c4a0(70)]>",
    "<NSLayoutConstraint:0xf544940 H:|-(20)-[PHStarsView:0x9d9c4a0]   (Names: '|':UITableViewCellContentView:0x9fcd710 )>",
    "<NSLayoutConstraint:0xf543d90 H:[PHStarsView:0x9d9c4a0]-(80)-|   (Names: '|':UITableViewCellContentView:0x9fcd710 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x9d774e0 h=--& v=--& H:[UITableViewCellContentView:0x9fcd710(320)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x9d56270 H:[PHStarsView:0x9d9c4a0(70)]>

【问题讨论】:

  • 你有一个 NSAutoresizingMaskLayoutConstraint 冲突。那些自动调整大小的约束往往与常规约束相冲突。如果以编程方式添加,请确保 UITableViewCell.contentView.subviews 都是 subview.setTranslatesAutoresizingMaskIntoConstraints(false)

标签: ios objective-c iphone uitableview ios7


【解决方案1】:

我在使用自定义 UITableViewCell 笔尖时遇到了同样的问题。关于解除分配单元格的一些事情会打破约束。

尝试添加

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewAutomaticDimension;
}

【讨论】:

  • 这为我解决了问题。一定是自动布局中的错误。
【解决方案2】:

您正在向视图添加约束,但您单元格的contentView 上的translatesAutoresizingMaskIntoConstraints 设置为YES。将其设置为 NO - 您显然希望控制约束而不使用 iOS 的默认设置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-09
    • 2012-12-28
    • 1970-01-01
    • 2014-10-27
    相关资源
    最近更新 更多