【问题标题】:Basic UIAlertController Unable to satisfy constraints基本 UIAlertController 无法满足约束
【发布时间】:2017-06-08 10:23:43
【问题描述】:
 UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title
                                                                         message:message
                                                                  preferredStyle:UIAlertControllerStyleAlert];

[alertController show];

此代码导致以下错误:

...[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:0x7af32260 h=-&- v=-&- UITransitionView:0x7ae60c70.height == UIWindow:0x7aebc600.height   (active)>",
"<NSAutoresizingMaskLayoutConstraint:0x7af9b6f0 h=--- v=--- UIWindow:0x7aebc600.height == 0   (active)>",
"<NSLayoutConstraint:0x79f1f050 UIView:0x7ae6ec40.height >= 44   (active)>",
"<NSLayoutConstraint:0x79f1d6a0 _UIAlertControllerView:0x7a26ce00'Error'.height == UIView:0x7ae6ec40.height   (active)>",
"<NSLayoutConstraint:0x7aafb360 _UIAlertControllerView:0x7a26ce00'Error'.centerY == UITransitionView:0x7ae60c70.centerY   (active)>",
"<NSLayoutConstraint:0x7afb81e0 V:|-(>=0)-[_UIAlertControllerView:0x7a26ce00'Error']   (active, names: '|':UITransitionView:0x7ae60c70 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x79f1f050 UIView:0x7ae6ec40.height >= 44   (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.

注意:在我的应用正在做的更广泛的背景下,我别无选择,只能使用[alertController show]

【问题讨论】:

  • a UIAlertController 实例的 layout 不应该由您管理...您只需呈现它,其余的由 UIKit 处理 AlertControllers 的方式处理。我猜你添加了一个不应该添加 any 的约束。
  • 我没有添加任何内容。上面的代码 sn-p 就是我正在做的所有事情
  • 谷歌搜索“将尝试通过打破约束来恢复”我能够在 stackoverflow 上找到许多问题,包括:this question。看看
  • 但我没有修改/添加/删除任何约束。我只是在创建一个警报控制器并尝试显示它
  • 我经常使用UIAlertController,但从未见过这种情况。请在您显示的内容周围添加代码。您未在此处显示的内容一定有问题。

标签: objective-c autolayout uialertcontroller


【解决方案1】:

你有UIWindow:0x7aebc600.height == 0。我猜测是你的问题。

显然你的窗口高度不应该设置为 0,否则你添加到它的任何东西都没有足够的高度。

另外你可以从here 找到一个非常好的调试教程。在页面上搜索“将尝试通过打破约束来恢复”

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-28
    • 1970-01-01
    • 1970-01-01
    • 2014-10-27
    • 2014-06-19
    相关资源
    最近更新 更多