首页 > 解决方案 > 我使用 UIAlertControllerStyleActionSheet 创建了一个 UIAlertController 然后添加了一些按钮,但提示我有布局问题

问题描述

我使用 UIAlertControllerStyleActionSheet 创建了一个 UIAlertController,然后添加了一些按钮,但提示我有布局问题。我确定我的代码没问题,但我不知道问题出在哪里,如果您知道原因,请告诉我。我将样式测试为 UIAlertControllerStyleAlert 并且没有这个问题。

我的项目只支持iphone,不支持iPad。我的开发环境:Xcode:10.2.1,iOS:12.3.1

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"title" message:@"message" preferredStyle:UIAlertControllerStyleActionSheet];

    UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"cancle" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
        //NSLog(@"");
    }];

    UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"sure" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        //NSLog(@"");
    }];

    [alertController addAction:cancleAction];
    [alertController addAction:sureAction];
    [self presentViewController:alertController animated:true completion:nil];

调试输出区打印:

[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:0x282e9c5a0 UIView:0x1019286f0.width == -16>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x282e9c5a0 UIView:0x1019286f0.width == -16>

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.

标签: iosobjective-c

解决方案


推荐阅读