3

理解できない Autolayout エラーが発生します。

2013-03-14 18:30:48.842 driver[7177:907] 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:0x1ede73e0 UILabel:0x1ede4320.top == PriceCell:0x1edcd0c0.top + 160>",
    "<NSLayoutConstraint:0x1ede7460 V:[UILabel:0x1ede4320]-(7)-[UIImageView:0x1ede45d0]>",
    "<NSLayoutConstraint:0x1ede74a0 UIImageView:0x1ede45d0.centerY == UIImageView:0x1f856810.centerY>",
    "<NSLayoutConstraint:0x1ede7880 UIImageView:0x1f856810.top == PriceCell:0x1edcd0c0.top + 30>",
    "<NSLayoutConstraint:0x1ede78c0 UIImageView:0x1f856810.bottom == PriceCell:0x1edcd0c0.bottom>",
    "<NSAutoresizingMaskLayoutConstraint:0x1f83f340 h=--& v=--& V:[PriceCell:0x1edcd0c0(300)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x1ede7460 V:[UILabel:0x1ede4320]-(7)-[UIImageView:0x1ede45d0]>

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.

問題: エラー リストから、autolayout が参照している ui 要素を特定できません。そこで、ストーリーボードに戻り、tableviewcell の各 UI 要素にフィールド Restoration Id の識別子を割り当てました。エラーメッセージの16進数が、対応するUI要素に割り当てた名前に置き換えられることをどこかで読みました。しかし残念ながら、これは起こっていません。では、ここで何が間違っているのか、何が欠けているのでしょうか?

4

1 に答える 1

0

エラーの原因となっているレイアウト制約の破れを確認しました。

私が間違っていなければ、レイアウトは次のようになります。 ここに画像の説明を入力

したがって、次のような制約を設定したようです。

•   Vertical space between cell top and label top is 160. So your label will be 160 px down from cell top.
•   Then you have set vertical space between label and imageView1 is 7 px.
•   Then you made centre Y between imageView1 and imageView2 to 0 px. So their centre will be same.
•   Then you set vertical space between imageView2 and cell top is 30 px.
•   Then you set vertical space between image view bottom and cell bottom is 0 px.
•   It seems that your cell height is 300 px.

この制約はすべて、1 つの制約を満たすためだけに壊れています。

では、「 160 + label.height + 7 + UIImageView1.height 」の制約を満たすにはどうすればよいでしょうか。

セルの高さは、ラベルの合計高さ + imageView1 + y + 7 の 160 px よりも小さいようです。

合計がセルの高さである 300 を超えているようで、imageView1 と imageView2 の両方の中心 Y が中心を 0 に合わせようとしています。

于 2015-04-13T13:42:23.087 に答える