UIAlertView给出约束错误

时间:2019-04-18 08:25:40

标签: autolayout uialertview nslayoutconstraint

我有以下代码,可在我的应用程序出现问题时用不同的消息显示警报。 该代码已经运行了好几年,并且在我在App Store的大多数应用程序中都可以使用。

我正在制作一个新的应用程序,并只是在其中添加了此代码,但是我在控制台中看到以下错误消息,这是我无法摆脱的。

约束消息指的是警报宽度,但是我没有设置约束,也没有任何方法可以使警告静音。

有人可以告知发生了什么事吗?

谢谢

-(void)errorMessage:(id)sender
{

    UIAlertController *alert = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Information",)
                                                                   message:displaymessage
                                                            preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *firstAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK",)
                                                          style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
                                                              [self dismissViewControllerAnimated:NO completion:nil];
                                                          }];

    [alert addAction:firstAction];
    [self presentViewController:alert animated:YES completion:nil];
}

2019-04-18 09:17:54.785207+0100 TestInputView5[1380:28232] [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:0x600001e15b30 UIView:0x7fe60c6104e0.width == - 16   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600001e15b30 UIView:0x7fe60c6104e0.width == - 16   (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.

1 个答案:

答案 0 :(得分:1)

我在俄罗斯论坛上找到了解决方案。 它看起来像魔术,但是有效。 您需要做两件事: 1)将空视图添加到警报 2)在没有动画的情况下显示

alert.view.addSubview(UIView()) // I can't explain it, but it works!

self.present(alert, animated: false)

论坛积分:https://quares.ru/?id=33972

帖子是机器翻译的,所以我想某处应该有英文原件(我找不到)