2

I have created custom view for UITableView cell. When The app runs and the UITableView gets populated I gets too much design related warning.Let me quickly share the log for design i am getting

    [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:0x600000a8c530 H:[UIView:0x7fcc025a6390]-(1)-|   (active, names: '|':UIView:0x7fcc025a5dc0 )>",
    "<NSLayoutConstraint:0x600000a8c620 H:|-(1)-[UIView:0x7fcc025a6390]   (active, names: '|':UIView:0x7fcc025a5dc0 )>",
    "<NSLayoutConstraint:0x600000a8cb20 H:|-(0)-[UIView:0x7fcc025a5dc0]   (active, names: '|':UITableViewCellContentView:0x7fcc025a58a0 )>",
    "<NSLayoutConstraint:0x600000a8cbc0 H:[UIView:0x7fcc025a5dc0]-(0)-|   (active, names: '|':UITableViewCellContentView:0x7fcc025a58a0 )>",
    "<NSLayoutConstraint:0x600000a8d5c0 'UIView-Encapsulated-Layout-Width' UITableViewCellContentView:0x7fcc025a58a0.width == 0   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600000a8c530 H:[UIView:0x7fcc025a6390]-(1)-|   (active, names: '|':UIView:0x7fcc025a5dc0 )>

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.
2020-07-16 12:52:06.760595+0500 NeverEndingApp[4395:106090] [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:0x600000a8c1c0 V:[UIView:0x7fcc025a6ad0]-(0)-|   (active, names: '|':UIView:0x7fcc025a6390 )>",
    "<NSLayoutConstraint:0x600000a8c260 V:|-(0)-[UIView:0x7fcc025a6ad0]   (active, names: '|':UIView:0x7fcc025a6390 )>",
    "<NSLayoutConstraint:0x600000a8c580 V:|-(1)-[UIView:0x7fcc025a6390]   (active, names: '|':UIView:0x7fcc025a5dc0 )>",
    "<NSLayoutConstraint:0x600000a8c5d0 V:[UIView:0x7fcc025a6390]-(1)-|   (active, names: '|':UIView:0x7fcc025a5dc0 )>",
    "<NSLayoutConstraint:0x600000a8cad0 V:|-(0)-[UIView:0x7fcc025a5dc0]   (active, names: '|':UITableViewCellContentView:0x7fcc025a58a0 )>",
    "<NSLayoutConstraint:0x600000a8cb70 V:[UIView:0x7fcc025a5dc0]-(0)-|   (active, names: '|':UITableViewCellContentView:0x7fcc025a58a0 )>",
    "<NSLayoutConstraint:0x600000a8d610 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7fcc025a58a0.height == 0   (active)>"
)

Following is the view design

The is the view I have designed

Now I dont know that what are the reasons which are creating the issue. Because the end result is satisfactory and as per desired.

So following I wanted to know:

  1. How to find out the exact issue in the design
  2. How to find out which view and which constraint of the view is creating problem
  3. Is it really important to remove these warnings since I am getting design as expected

Note: I know there are millions of threads here on SO for the similar issue but most of them are outdated and old. I am also asking it just to know the perfect way to avoid these issues and also the easy and best way to track the issue.

A.s.ALI
  • 1,992
  • 3
  • 22
  • 54
  • 2
    Use https://www.wtfautolayout.com/. It shows that your cell height should be zero. What row height have you set? Automatic? – Paulw11 Jul 16 '20 at 10:29
  • Did you ever read and try the suggestions in the error? – vadian Jul 16 '20 at 10:36
  • You can look into this error. `Will attempt to recover by breaking constraint ` It seems that this constraint is conflicted. You should track by view id such as `0x600000a8c530` – Omer Faruk Ozturk Jul 16 '20 at 10:41
  • @Paulw11 yes automatic via code. And in IB it is set to 50 – A.s.ALI Jul 16 '20 at 11:52
  • @vadian I am not abe to understand the suggestions – A.s.ALI Jul 16 '20 at 11:52
  • @omerfarukozturk that is what I am asking . how to track the issue how to start the process – A.s.ALI Jul 16 '20 at 11:53
  • 1
    You can find which element/constraints causes the issue searching the `address` (ex: `0x7fcc025a6390`) of it, as referenced in [this](https://stackoverflow.com/a/47018422/3835963) answer. There is a conflict for horizontal (`H: `) constraints. – Omer Faruk Ozturk Jul 16 '20 at 12:41
  • @omerfarukozturk cool. So what thing should I check up on first. I have shared logs already. What you think what should I check at first – A.s.ALI Jul 17 '20 at 05:23
  • 1
    You should check the constraints and view that specified in error ` ` You can remove them and start adding again. Also check [this](https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/AutolayoutPG/DebuggingTricksandTips.html#//apple_ref/doc/uid/TP40010853-CH21-SW1) link. – Omer Faruk Ozturk Jul 17 '20 at 06:45
  • ok that good. I wish some one post more deep explanation in answer. Any how thanks – A.s.ALI Jul 17 '20 at 07:17
  • @omerfarukozturk I dont know how to check this – A.s.ALI Jul 17 '20 at 07:59
  • I added an answer for the steps i suggested to find related view/constraint. Next step you can try them. – Omer Faruk Ozturk Jul 17 '20 at 08:35

1 Answers1

5

The error message shows there are conflicting constraints. Not all of these constraints can be true at the same time. You need to either remove one or edit.

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600000a8c530 H:[UIView:0x7fcc025a6390]-(1)-|   (active, names: '|':UIView:0x7fcc025a5dc0 )>

You can take some steps to identify the issue:

  1. Show Debug View Hierarchy

enter image description here

  1. Search and find constraints and views that causes the issue (0x600000a8c530, 0x7fcc025a6390) as referenced to this answer.

enter image description here

  1. Then try to investigate the conflict.

You can also check these documentations to get more info.

Omer Faruk Ozturk
  • 1,722
  • 13
  • 25
  • now you have mentioned the statement that is causing warning. Now how to know what this warning is trying to say ? – A.s.ALI Jul 17 '20 at 10:09
  • `Unable to simultaneously satisfy constraints.` means you have constraints that conflict with each other and can't all be accommodated. So the Auto Layout system needs to ignore (at least) one of them. Which constraint is disabled by the system is pointed out in the log (under `Will attempt to recover by breaking constraint`). The constraints in the logs are described using the visual format language, see: https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/AutolayoutPG/VisualFormatLanguage.html – wolfrevo Jul 24 '20 at 23:01