问题
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title
message:message
preferredStyle:UIAlertControllerStyleAlert];
[alertController show];
This code is causing the following error:
...[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.
Note: In the wider context of what my app is doing, I have no choice but to use [alertController show]
回答1:
You have UIWindow:0x7aebc600.height == 0
. I'm guessing that your issue.
Obviously your window height shouldn't be set to 0, otherwise whatever that you add to it won't have enough height.
Additionally you can find a very good debugging tutorial from here. On the page search for "Will attempt to recover by breaking constraint"
来源:https://stackoverflow.com/questions/44425217/basic-uialertcontroller-unable-to-satisfy-constraints