首页 > 解决方案 > 动态设置 navigationItem.prompt 时获取 LayoutConstraints 警告

问题描述

从数据任务获得结果后,我试图动态设置 navigationItem.prompt。当 datatask 完成时,datatask 本身的数据会在 tableview 中列出,并且 tableview 中列出的项目数应该显示在 navigationItem.prompt 中。

但是,当尝试将提示从 nil 设置为字符串时,我收到下面的 LayoutConstraint 警告。

经过一番研究,我在本教程中找到了一个类似的示例(请参阅延迟任务执行)。在初始视图显示并等待设置提示后,会显示相同的警告。

2019-07-29 13:48:58.337732+0200 GooglyPuff[34677:3058108] [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. 
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x600003c852c0 h=--& v=--& _UINavigationBarModernPromptView:0x7ff015c26540.width == 0   (active)>",
    "<NSLayoutConstraint:0x600003c84e10 UILabel:0x7ff015e24660'Add photos with faces to ...'.centerX == _UINavigationBarModernPromptView:0x7ff015c26540.centerX   (active)>",
    "<NSLayoutConstraint:0x600003c850e0 UILabel:0x7ff015e24660'Add photos with faces to ...'.trailing <= UILayoutGuide:0x6000026bc000'UIViewLayoutMarginsGuide'.trailing   (active)>",
    "<NSLayoutConstraint:0x600003c84f50 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x6000026bc000'UIViewLayoutMarginsGuide']-(20)-|(LTR)   (active, names: '|':_UINavigationBarModernPromptView:0x7ff015c26540 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600003c850e0 UILabel:0x7ff015e24660'Add photos with faces to ...'.trailing <= UILayoutGuide:0x6000026bc000'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.
2019-07-29 13:48:58.339602+0200 GooglyPuff[34677:3058108] [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. 
    (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x600003c852c0 h=--& v=--& _UINavigationBarModernPromptView:0x7ff015c26540.width == 0   (active)>",
    "<NSLayoutConstraint:0x600003c84e10 UILabel:0x7ff015e24660'Add photos with faces to ...'.centerX == _UINavigationBarModernPromptView:0x7ff015c26540.centerX   (active)>",
    "<NSLayoutConstraint:0x600003c84fa0 UILabel:0x7ff015e24660'Add photos with faces to ...'.leading >= UILayoutGuide:0x6000026bc000'UIViewLayoutMarginsGuide'.leading   (active)>",
    "<NSLayoutConstraint:0x600003c84eb0 'UIView-leftMargin-guide-constraint' H:|-(20)-[UILayoutGuide:0x6000026bc000'UIViewLayoutMarginsGuide'](LTR)   (active, names: '|':_UINavigationBarModernPromptView:0x7ff015c26540 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600003c84fa0 UILabel:0x7ff015e24660'Add photos with faces to ...'.leading >= UILayoutGuide:0x6000026bc000'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.

标签: iosuinavigationcontrolleruinavigationbarnslayoutconstraint

解决方案


推荐阅读