UITableViewCell自动布局约束问题

时间:2017-08-03 03:36:18

标签: ios swift xcode uitableview autolayout

我在调试器中收到Unable to simultaneously satisfy constraints.错误。我知道这种类型的问题已被多次询问,我知道如何跟踪约束以查看问题所在 - 但这个问题对我来说毫无意义。我正在使用UITableViewAutomaticDimension功能自动调整我的单元格大小。以下是我的约束。为了简化图像,除了postTextView之外,图像上的每个对象都具有指定的高度,后者具有灵活的高度,因此可以使用不同的文本量进行扩展。我希望其他一切都有一个特定的高度。

一旦约束被打破,因为它声明它将在控制台中尝试,屏幕上的布局是正确的,一切都像我期望的那样。

enter image description here

以下是运行应用时出现的错误:

2017-08-02 23:29:29.932838-0400 StudyHub[35782:3472431] [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:0x60400048e9c0 UIImageView:0x7fe16cd55110.height == 55   (active)>",
"<NSLayoutConstraint:0x60400048b680 UIButton:0x7fe16cd5a1d0'0'.height == 25   (active)>",
"<NSLayoutConstraint:0x60400048ee70 UIStackView:0x7fe16cd5cf60.height == 308   (active)>",
"<NSLayoutConstraint:0x60400048f550 V:|-(8)-[UIImageView:0x7fe16cd55110]   (active, names: '|':UIView:0x7fe16cd543b0 )>",
"<NSLayoutConstraint:0x60400048f640 V:[UIImageView:0x7fe16cd55110]-(8)-[UITextView:0x7fe16d8ff000'This is a test of the pos...']   (active)>",
"<NSLayoutConstraint:0x60400048f780 V:[UITextView:0x7fe16d8ff000'This is a test of the pos...']-(8)-[UIStackView:0x7fe16cd5cf60]   (active)>",
"<NSLayoutConstraint:0x60400048f8c0 V:[UIStackView:0x7fe16cd5cf60]-(8)-[UIButton:0x7fe16cd5a1d0'0']   (active)>",
"<NSLayoutConstraint:0x60400048f910 V:[UIButton:0x7fe16cd5a1d0'0']-(8)-|   (active, names: '|':UIView:0x7fe16cd543b0 )>",
"<NSLayoutConstraint:0x60400048fb90 V:|-(8)-[UIView:0x7fe16cd543b0]   (active, names: '|':UITableViewCellContentView:0x7fe16cd53650 )>",
"<NSLayoutConstraint:0x60400048fc30 V:[UIView:0x7fe16cd543b0]-(8)-|   (active, names: '|':UITableViewCellContentView:0x7fe16cd53650 )>",
"<NSLayoutConstraint:0x600000499460 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7fe16cd53650.height == 50   (active)>"
)

    Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60400048ee70 UIStackView:0x7fe16cd5cf60.height == 308   (active)>

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.
2017-08-02 23:29:29.962013-0400 StudyHub[35782:3472431] [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:0x60400048e9c0 UIImageView:0x7fe16cd55110.height == 55   (active)>",
"<NSLayoutConstraint:0x60400048b680 UIButton:0x7fe16cd5a1d0'0'.height == 25   (active)>",
"<NSLayoutConstraint:0x60400048f550 V:|-(8)-[UIImageView:0x7fe16cd55110]   (active, names: '|':UIView:0x7fe16cd543b0 )>",
"<NSLayoutConstraint:0x60400048f640 V:[UIImageView:0x7fe16cd55110]-(8)-[UITextView:0x7fe16d8ff000'This is a test of the pos...']   (active)>",
"<NSLayoutConstraint:0x60400048f780 V:[UITextView:0x7fe16d8ff000'This is a test of the pos...']-(8)-[UIStackView:0x7fe16cd5cf60]   (active)>",
"<NSLayoutConstraint:0x60400048f8c0 V:[UIStackView:0x7fe16cd5cf60]-(8)-[UIButton:0x7fe16cd5a1d0'0']   (active)>",
"<NSLayoutConstraint:0x60400048f910 V:[UIButton:0x7fe16cd5a1d0'0']-(8)-|   (active, names: '|':UIView:0x7fe16cd543b0 )>",
"<NSLayoutConstraint:0x60400048fb90 V:|-(8)-[UIView:0x7fe16cd543b0]   (active, names: '|':UITableViewCellContentView:0x7fe16cd53650 )>",
"<NSLayoutConstraint:0x60400048fc30 V:[UIView:0x7fe16cd543b0]-(8)-|   (active, names: '|':UITableViewCellContentView:0x7fe16cd53650 )>",
"<NSLayoutConstraint:0x6000004990f0 'UISV-canvas-connection' UIStackView:0x7fe16cd5cf60.top == UIStackView:0x7fe16cd5d9c0.top   (active)>",
"<NSLayoutConstraint:0x600000498fb0 'UISV-canvas-connection' V:[UIStackView:0x7fe16cd5e110]-(0)-|   (active, names: '|':UIStackView:0x7fe16cd5cf60 )>",
"<NSLayoutConstraint:0x600000499190 'UISV-fill-equally' UIStackView:0x7fe16cd5e110.height == UIStackView:0x7fe16cd5d9c0.height   (active)>",
"<NSLayoutConstraint:0x6000004991e0 'UISV-spacing' V:[UIStackView:0x7fe16cd5d9c0]-(8)-[UIStackView:0x7fe16cd5e110]   (active)>",
"<NSLayoutConstraint:0x600000499460 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7fe16cd53650.height == 50   (active)>"
)

    Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x6000004991e0 'UISV-spacing' V:[UIStackView:0x7fe16cd5d9c0]-(8)-[UIStackView:0x7fe16cd5e110]   (active)>

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.
2017-08-02 23:29:29.963167-0400 StudyHub[35782:3472431] [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:0x60400048e9c0 UIImageView:0x7fe16cd55110.height == 55   (active)>",
"<NSLayoutConstraint:0x60400048b680 UIButton:0x7fe16cd5a1d0'0'.height == 25   (active)>",
"<NSLayoutConstraint:0x60400048f550 V:|-(8)-[UIImageView:0x7fe16cd55110]   (active, names: '|':UIView:0x7fe16cd543b0 )>",
"<NSLayoutConstraint:0x60400048f640 V:[UIImageView:0x7fe16cd55110]-(8)-[UITextView:0x7fe16d8ff000'This is a test of the pos...']   (active)>",
"<NSLayoutConstraint:0x60400048f780 V:[UITextView:0x7fe16d8ff000'This is a test of the pos...']-(8)-[UIStackView:0x7fe16cd5cf60]   (active)>",
"<NSLayoutConstraint:0x60400048f8c0 V:[UIStackView:0x7fe16cd5cf60]-(8)-[UIButton:0x7fe16cd5a1d0'0']   (active)>",
"<NSLayoutConstraint:0x60400048f910 V:[UIButton:0x7fe16cd5a1d0'0']-(8)-|   (active, names: '|':UIView:0x7fe16cd543b0 )>",
"<NSLayoutConstraint:0x60400048fb90 V:|-(8)-[UIView:0x7fe16cd543b0]   (active, names: '|':UITableViewCellContentView:0x7fe16cd53650 )>",
"<NSLayoutConstraint:0x60400048fc30 V:[UIView:0x7fe16cd543b0]-(8)-|   (active, names: '|':UITableViewCellContentView:0x7fe16cd53650 )>",
"<NSLayoutConstraint:0x600000499460 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7fe16cd53650.height == 50   (active)>"
)

    Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60400048e9c0 UIImageView:0x7fe16cd55110.height == 55   (active)>

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.
2017-08-02 23:29:29.963961-0400 StudyHub[35782:3472431] [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:0x60400048b680 UIButton:0x7fe16cd5a1d0'0'.height == 25   (active)>",
"<NSLayoutConstraint:0x60400048f550 V:|-(8)-[UIImageView:0x7fe16cd55110]   (active, names: '|':UIView:0x7fe16cd543b0 )>",
"<NSLayoutConstraint:0x60400048f640 V:[UIImageView:0x7fe16cd55110]-(8)-[UITextView:0x7fe16d8ff000'This is a test of the pos...']   (active)>",
"<NSLayoutConstraint:0x60400048f780 V:[UITextView:0x7fe16d8ff000'This is a test of the pos...']-(8)-[UIStackView:0x7fe16cd5cf60]   (active)>",
"<NSLayoutConstraint:0x60400048f8c0 V:[UIStackView:0x7fe16cd5cf60]-(8)-[UIButton:0x7fe16cd5a1d0'0']   (active)>",
"<NSLayoutConstraint:0x60400048f910 V:[UIButton:0x7fe16cd5a1d0'0']-(8)-|   (active, names: '|':UIView:0x7fe16cd543b0 )>",
"<NSLayoutConstraint:0x60400048fb90 V:|-(8)-[UIView:0x7fe16cd543b0]   (active, names: '|':UITableViewCellContentView:0x7fe16cd53650 )>",
"<NSLayoutConstraint:0x60400048fc30 V:[UIView:0x7fe16cd543b0]-(8)-|   (active, names: '|':UITableViewCellContentView:0x7fe16cd53650 )>",
"<NSLayoutConstraint:0x600000499460 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7fe16cd53650.height == 50   (active)>"
)

    Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60400048b680 UIButton:0x7fe16cd5a1d0'0'.height == 25   (active)>

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.
2017-08-02 23:29:29.964742-0400 StudyHub[35782:3472431] [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:0x60400048f550 V:|-(8)-[UIImageView:0x7fe16cd55110]   (active, names: '|':UIView:0x7fe16cd543b0 )>",
"<NSLayoutConstraint:0x60400048f640 V:[UIImageView:0x7fe16cd55110]-(8)-[UITextView:0x7fe16d8ff000'This is a test of the pos...']   (active)>",
"<NSLayoutConstraint:0x60400048f780 V:[UITextView:0x7fe16d8ff000'This is a test of the pos...']-(8)-[UIStackView:0x7fe16cd5cf60]   (active)>",
"<NSLayoutConstraint:0x60400048f8c0 V:[UIStackView:0x7fe16cd5cf60]-(8)-[UIButton:0x7fe16cd5a1d0'0']   (active)>",
"<NSLayoutConstraint:0x60400048f910 V:[UIButton:0x7fe16cd5a1d0'0']-(8)-|   (active, names: '|':UIView:0x7fe16cd543b0 )>",
"<NSLayoutConstraint:0x60400048fb90 V:|-(8)-[UIView:0x7fe16cd543b0]   (active, names: '|':UITableViewCellContentView:0x7fe16cd53650 )>",
"<NSLayoutConstraint:0x60400048fc30 V:[UIView:0x7fe16cd543b0]-(8)-|   (active, names: '|':UITableViewCellContentView:0x7fe16cd53650 )>",
"<NSLayoutConstraint:0x600000499460 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7fe16cd53650.height == 50   (active)>"
)

    Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60400048f640 V:[UIImageView:0x7fe16cd55110]-(8)-[UITextView:0x7fe16d8ff000'This is a test of the pos...']   (active)>

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.

2 个答案:

答案 0 :(得分:0)

似乎您还需要在imageView上设置宽度约束。您还可以通过单击下面的调试视图层次结构来尝试调试autolayout约束。 enter image description here

答案 1 :(得分:0)

在Swift 4中我正在创建一个演示项目: - 根据你的UIViewController。

  

UIViewController演示:   enter image description here   enter image description here

请检查我希望它会起作用的约束: -