Reputation: 85
I am new in iOS development. i am creating a chat app with autolayouts but i am getting "breaking constraint" whenever i open collectionview in my app. Here error which i get
2017-11-06 07:34:52.838630+0530 ChatHub[4083:306096] [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:0x6040002989c0 BubbleView.width == 205.938 (active, names: BubbleView:0x7ffde3611880 )>",
"<NSLayoutConstraint:0x604000298600 ProfileImageView.width == 32 (active, names: ProfileImageView:0x7ffde3611a60 )>",
"<NSLayoutConstraint:0x60400028d890 H:|-(8)-[ProfileImageView](LTR) (active, names: ProfileImageView:0x7ffde3611a60, '|':ChatHub.ChatMessageCell:0x7ffde360e670 )>",
"<NSLayoutConstraint:0x6040002988d0 H:[ProfileImageView]-(8)-[BubbleView](LTR) (active, names: BubbleView:0x7ffde3611880, ProfileImageView:0x7ffde3611a60 )>",
"<NSLayoutConstraint:0x604000298880 BubbleView.right == ChatHub.ChatMessageCell:0x7ffde360e670.right - 8 (active, names: BubbleView:0x7ffde3611880 )>",
"<NSLayoutConstraint:0x6000004870d0 'UIView-Encapsulated-Layout-Width' ChatHub.ChatMessageCell:0x7ffde360e670.width == 375 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x6040002989c0 BubbleView.width == 205.938 (active, names: BubbleView:0x7ffde3611880 )>
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-11-06 07:34:53.041831+0530 ChatHub[4083:306096] [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:0x600000485c30 BubbleView.width == 205.938 (active, names: BubbleView:0x7ffde345dfb0 )>",
"<NSLayoutConstraint:0x600000485aa0 ProfileImageView.width == 32 (active, names: ProfileImageView:0x7ffde345e190 )>",
"<NSLayoutConstraint:0x600000485a00 H:|-(8)-[ProfileImageView](LTR) (active, names: ProfileImageView:0x7ffde345e190, '|':ChatHub.ChatMessageCell:0x7ffde345b380 )>",
"<NSLayoutConstraint:0x600000485b40 BubbleView.right == ChatHub.ChatMessageCell:0x7ffde345b380.right - 8 (active, names: BubbleView:0x7ffde345dfb0 )>",
"<NSLayoutConstraint:0x600000485b90 H:[ProfileImageView]-(8)-[BubbleView](LTR) (active, names: BubbleView:0x7ffde345dfb0, ProfileImageView:0x7ffde345e190 )>",
"<NSLayoutConstraint:0x60400029a810 'UIView-Encapsulated-Layout-Width' ChatHub.ChatMessageCell:0x7ffde345b380.width == 375 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x600000485c30 BubbleView.width == 205.938 (active, names: BubbleView:0x7ffde345dfb0 )>
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.
How can i fix this. i am stuck here from last 2 days .. please help
i get error in above screenshot but i don't get one in below
Upvotes: 3
Views: 596
Reputation: 2163
As far as I can see your horizontal constraints for this cell look like this.
H:|-8-[ProfileImageView(=32)]-8-[BubbleView(=206)]-8-|
So pretty much your layout is fine when your view's width is equal to the sum of widths of all its subviews and spaces around them (which is 254). Troubles start when the cell gets wider (or narrower).
Here you can see that your configured width conflicts with the encapsulated width of your cell (which is 375).
<NSLayoutConstraint:0x6000004870d0 'UIView-Encapsulated-Layout-Width' ChatHub.ChatMessageCell:0x7ffde360e670.width == 375 (active)>
If you want to keep the width of the profile image and the bubble view fixed. I recommend you to set the sign of the constraint below (BubbleView.right
) to the greater than or equal.
<NSLayoutConstraint:0x604000298880 BubbleView.right == ChatHub.ChatMessageCell:0x7ffde360e670.right - 8 (active, names: BubbleView:0x7ffde3611880 )>
Another option is ensuring that the width of your cell is always equal to 254 which a bit harder to achieve.
Upvotes: 1
Reputation: 484
According to the error info, it seems that you create a BubbleView
and a ProfileImageView
side by side. The autolayout constraint is
(left edge)| - (8) - Profile(32) - (8) -- Bubble -- (8)| (cell right edge)
Notice that as long as the width of the cell is determined, that Bubble size can be automatically calculated by cell.width - 8 - 32 - 8 - 8
. So the constraint of bubble width is redundant. Just remove it.
Upvotes: 0