【发布时间】: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