5

I am using a navigation bar with a prompt, looking like this: enter image description here

I receive the following auto layout warnings in the console:

2019-09-01 21:26:03.225576+0200 Hortus[85622:2386450] [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:0x600002d16990 UILabel:0x7fc9eb816f50'Testen'.centerX == _UINavigationBarModernPromptView:0x7fc9ebe27780.centerX   (active)>",
    "<NSLayoutConstraint:0x600002d15c20 UILabel:0x7fc9eb816f50'Testen'.leading >= UILayoutGuide:0x6000037571e0'UIViewLayoutMarginsGuide'.leading   (active)>",
    "<NSLayoutConstraint:0x600002d10ff0 '_UITemporaryLayoutWidth' _UINavigationBarModernPromptView:0x7fc9ebe27780.width == 0   (active)>",
    "<NSLayoutConstraint:0x600002d16a30 'UIView-leftMargin-guide-constraint' H:|-(8)-[UILayoutGuide:0x6000037571e0'UIViewLayoutMarginsGuide'](LTR)   (active, names: '|':_UINavigationBarModernPromptView:0x7fc9ebe27780 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600002d15c20 UILabel:0x7fc9eb816f50'Testen'.leading >= UILayoutGuide:0x6000037571e0'UIViewLayoutMarginsGuide'.leading   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.

2019-09-01 21:26:03.226198+0200 Hortus[85622:2386450] [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:0x600002d16990 UILabel:0x7fc9eb816f50'Testen'.centerX == _UINavigationBarModernPromptView:0x7fc9ebe27780.centerX   (active)>",
    "<NSLayoutConstraint:0x600002d15540 UILabel:0x7fc9eb816f50'Testen'.trailing <= UILayoutGuide:0x6000037571e0'UIViewLayoutMarginsGuide'.trailing   (active)>",
    "<NSLayoutConstraint:0x600002d10ff0 '_UITemporaryLayoutWidth' _UINavigationBarModernPromptView:0x7fc9ebe27780.width == 0   (active)>",
    "<NSLayoutConstraint:0x600002d14320 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x6000037571e0'UIViewLayoutMarginsGuide']-(8)-|(LTR)   (active, names: '|':_UINavigationBarModernPromptView:0x7fc9ebe27780 )>"

    "<NSAutoresizingMaskLayoutConstraint:0x60000043be30 h=--& v=--& _UINavigationBarModernPromptView:0x7fb3c6416640.width == 0   (active)>",
    "<NSLayoutConstraint:0x600000421400 UILabel:0x7fb3c66d8bf0'Plant guide'.centerX == _UINavigationBarModernPromptView:0x7fb3c6416640.centerX   (active)>",
    "<NSLayoutConstraint:0x600000421f90 UILabel:0x7fb3c66d8bf0'Plant guide'.trailing <= UILayoutGuide:0x600001e58fc0'UIViewLayoutMarginsGuide'.trailing   (active)>",
    "<NSLayoutConstraint:0x600000421e00 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x600001e58fc0'UIViewLayoutMarginsGuide']-(20)-|(LTR)   (active, names: '|':_UINavigationBarModernPromptView:0x7fb3c6416640 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600002d15540 UILabel:0x7fc9eb816f50'Testen'.trailing <= UILayoutGuide:0x6000037571e0'UIViewLayoutMarginsGuide'.trailing   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.

These warnings are given for the prompt in the navigation bar, but I do not set the autolayout constraints for the navigation bar. This should be handled by IOS itself.

What can I do to fix these warnings?

[Edit] The warnings are given in prepare() when segueing to the view controller. I set the prompt in prepare(). The segue is to a storyboard reference and is defined as 'present modally'. The storyboard reference references a UINavigationController. The prompt is set on the root view controller of the navigation controller.

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

    if let identifier = segue.identifier {
        switch identifier {

        case "editImage":
            let nc = segue.destination as? TTImageNavigationController
            if let rvc = nc?.rootViewController as? TTImageEditorController {
                rvc.navigationItem.prompt = navigationItem.prompt
            }

        default:
            break
        }
    }
}

[EDIT] It seems that the problem is not clear to most of the people who react. Again... I do not set any auto layout settings in code or storyboard. The problem occurs in the navigation bar after setting the prompt in the prepare() function prior to the segue. The code is given above. Any reactions that say that I have to change or check my constraints are not helpful, because there are no constraints to check!

[EDIT] As requested by Mohsen, I created a small sample project on github: https://bitbucket.org/Leontien/navigationbarautolayoutwarning/src/master/

Leontien
  • 612
  • 5
  • 22

4 Answers4

9

It’s not your bug. It’s Apple’s bug. Ignore the console. File a report with Apple and move on.

matt
  • 515,959
  • 87
  • 875
  • 1,141
1

Set priority to your constraints. This will fulfill constraints according to priority. Please refer this link.

Komal Goyani
  • 779
  • 6
  • 25
  • I am not sure how I can make it clear that I don't have any constraints!! The warnings are given for the navigation bar and I don't set any auto layout constraints for the navigation bar. – Leontien Sep 03 '19 at 12:46
  • Please check your image size which are putted in navigation bar, you may put images in Assets.xcassets. Also check title label of navigation bar. – Komal Goyani Sep 03 '19 at 12:58
  • Image size? I do not put an image in the navigation bar as you can see in the code in the description. I only set a string to the prompt of the navigation bar. – Leontien Sep 03 '19 at 13:14
1

you set centerX for the label and set leading and trailing for right and left buttons, also you didn't set any width constraint for UILabel

 "<NSLayoutConstraint:0x600002d16990 UILabel:0x7fc9eb816f50'Testen'.centerX == _UINavigationBarModernPromptView:0x7fc9ebe27780.centerX   (active)>",
"<NSLayoutConstraint:0x600002d15c20 UILabel:0x7fc9eb816f50'Testen'.leading >= UILayoutGuide:0x6000037571e0'UIViewLayoutMarginsGuide'.leading   (active)>",
"<NSLayoutConstraint:0x600002d10ff0 '_UITemporaryLayoutWidth' _UINavigationBarModernPromptView:0x7fc9ebe27780.width == 0   (active)>",
"<NSLayoutConstraint:0x600002d16a30 'UIView-leftMargin-guide-constraint' H:|-(8)-[UILayoutGuide:0x6000037571e0'UIViewLayoutMarginsGuide'](LTR)   (active, names: '|':_UINavigationBarModernPromptView:0x7fc9ebe27780 )>"

.

"<NSLayoutConstraint:0x600002d16990 UILabel:0x7fc9eb816f50'Testen'.centerX == _UINavigationBarModernPromptView:0x7fc9ebe27780.centerX   (active)>",
    "<NSLayoutConstraint:0x600002d15540 UILabel:0x7fc9eb816f50'Testen'.trailing <= UILayoutGuide:0x6000037571e0'UIViewLayoutMarginsGuide'.trailing   (active)>",
    "<NSLayoutConstraint:0x600002d10ff0 '_UITemporaryLayoutWidth' _UINavigationBarModernPromptView:0x7fc9ebe27780.width == 0   (active)>",
    "<NSLayoutConstraint:0x600002d14320 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x6000037571e0'UIViewLayoutMarginsGuide']-(8)-|(LTR)   (active, names: '|':_UINavigationBarModernPromptView:0x7fc9ebe27780 )>"

    "<NSAutoresizingMaskLayoutConstraint:0x60000043be30 h=--& v=--& _UINavigationBarModernPromptView:0x7fb3c6416640.width == 0   (active)>",
    "<NSLayoutConstraint:0x600000421400 UILabel:0x7fb3c66d8bf0'Plant guide'.centerX == _UINavigationBarModernPromptView:0x7fb3c6416640.centerX   (active)>",
    "<NSLayoutConstraint:0x600000421f90 UILabel:0x7fb3c66d8bf0'Plant guide'.trailing <= UILayoutGuide:0x600001e58fc0'UIViewLayoutMarginsGuide'.trailing   (active)>",
    "<NSLayoutConstraint:0x600000421e00 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x600001e58fc0'UIViewLayoutMarginsGuide']-(20)-|(LTR)   (active, names: '|':_UINavigationBarModernPromptView:0x7fb3c6416640 )>"

for solve this warning you should remove leading and trailing constraint from UILabel and set left button with leading to superview and right button's trailing to superview as well.

or you can use a navigation bar object, it has a label and also you can add barButtonItem to it.

you can add width constraint for the UILabel but it will be conflict on another devices when you run it on some other devices enter image description here

mohsen
  • 4,698
  • 1
  • 33
  • 54
  • You start with stating that I set some constraints and don’t set other constraints.... I don’t set any constraints at all! It is the default navigation bar that I use and I only set the strings for title and prompt. – Leontien Sep 06 '19 at 13:40
  • The default navigation bar has a uilabel and you don’t need add a UILabel – mohsen Sep 07 '19 at 02:43
  • why do you think that I add a UILabel? I use the default labels for title and prompt. – Leontien Sep 07 '19 at 05:42
  • @Leontien could you push a sample of your warning to a git repository? – mohsen Sep 07 '19 at 05:49
  • 1
    I edited my description and added a link to a sample project in GitHub. – Leontien Sep 07 '19 at 11:36
  • you locked your repository, so I push it in a new repository: https://bitbucket.org/mhview/naivationg2/src/master/ – mohsen Sep 07 '19 at 12:33
  • Sorry, I thought making it public was enough. It is the first time that I created a public repository. – Leontien Sep 07 '19 at 12:41
  • by the way , there is any problem, I saw your code and I realized you have a problem with prompt label, it just show you a warning and doesn't affect to your code. – mohsen Sep 07 '19 at 12:50
  • I don't understand your last comment. I know it is only a warning and my app is not affected. But what is causing the warning? – Leontien Sep 07 '19 at 13:00
  • @Leontien my answer answers that. Apple has a bug with its own constraints. It isn’t your problem. Ignore it. We all have the same thing with these UINavigationBarModernPromptView warnings. – matt Sep 07 '19 at 18:17
1

This helps to debug broken constraint issue by providing a more readable output

  • Create an extension for NSLayoutConstraint

extension NSLayoutConstraint {
    override open var description: String {
        let id = identifier ?? ""
        return "Constraint ID: \(id), constant: \(constant)"
    }
}
  • set a unique identifier for every constraint in the storyboard

  • you'll get a more readable output pointing out which constraint id is broken

  • change the priority for broken constraint

Brar
  • 111
  • 10